Woodstox provides a feature to peek into the next XML element from the current XML element. This is achieved by using
This sample program demonstrates how to peek into the next XML element.
Create the employee.xml as shown below.
Note that there are three XML elements:
- start element ’employee’
- character content ‘some text content’
- end element ’employee’
Create TestPeek class as shown below.
to get the start element (see line 26-39 below). Print the contents of start element (see line 28 below).
Once the start element is obtained then use
to peek into the next element which is the character text(see line 31 below). Print the contents of peek element (see line 35 below).
Note that according JSR-173 specification,
method returns the next element but does not take it off the stream.
The output of the program demonstrating peek functionality using Woodstox is shown below.
Download Source Code for this Program