Aalto StAX Parsing: Reading Namespace


This article demonstrates the how to read namespace related information using Aalto StAX parser.

Create employee.xml as shown below.

Note the namespace URI ‘https://studytrails.com’ (see line 1 below) and the namespace prefix ‘s’ used in all start and end elements.

Create TestReadNamespace as shown below.

Note that start element is obtained by using the StAX API (see lines 20-29 below).

The following API calls demonstrate reading of namespace related information:

  • For the ’employee’ start element, get the namespace count (see line 22 below)
  • Get the namespace prefix(see line 24 below)
  • Get the namespace URI(see line 25 below)

The output of the program demonstrating parsing of namespace related information is shown below.

Download Source Code for this Program

Leave a Comment