Woodstox provides excellent support for StAX (Streaming API for XML) parsing. Streaming API is used to parse large XML documents in a performance efficient manner. StAX compliant parsers do not load the entire XML document in memory but use a ‘Pull Model’ to load sections of document and parse it.
Woodstox is compliant with JSR-173 standard.
In the following program, we shall explore how to perform basic StAX parsing using Woodstox.
Create the sample XML file as shown below
Create the TestBasicStaxParsing parser as shown below.
Load the XML file as an
(see line 15 below).
class (see lines 16-17 below).
using hasNext() method (see line 18 below).
Get the event type using
‘s next() method (see line 19 below).
Based on the type of the event, extract the contents and print them to console (see lines 20-33 below).
The output of the program demonstrating basic StAX parsing is shown below: