Aalto provides JSR-173 compliant StAX (Streaming API for XML) parsing. The key classes involved in StAX parsing are
. The following sample program demonstrates how to perform basic StAX parsing
Create employee.xml as shown below. It contains employee related information like id, name and salary (see lines 2-4 below)
Create TestBasicStaxParsing class as shown below.
Load Aalto’s parser factory using the name ‘com.fasterxml.aalto.stax.InputFactoryImpl’ as shown in line 17 below)
as shown in line 18 below.
Then iterate through the xml stream reader by using
method (see line 19 below).
Get the event type (see line 20 below) and based on the type of element, extract parsed data (see lines 21-34 below)
The output of the program demonstrating basic StAX parsing is show below.