Woodstox : Read Attribute Of XML Element


This article demonstrates how to read the attribute in an XML element using Woodstox.

Create employee.xml as shown below. Note the attribute ‘id’ for the element ’employee’ (see line 1 below).

Create TestReadAttribute class as shown below.

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

The following API calls demonstrate reading of attribute:

  • For the ’employee’ start element, get the attribute count (see line 22 below)
  • Get the attribute name (see line 24 below)
  • Get the attribute value (see line 25 below)

The output of the program demonstrating reading of attributes is shown below:

Download Source Code for this Program

1 thought on “Woodstox : Read Attribute Of XML Element”

Leave a Comment