Woodstox : Read Namespace Of XML Start Element

Overview

This article demonstrates how to read namespace related information using Woodstox 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 class 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 how to read namespace related information is shown below:

Download Source Code for this Program

Leave a Comment