Aalto StAX Parsing: Reading XML Attribute

Overview

This article demonstrates how to read the attributes of an XML element using Aalto StAX parser.

Create employee.xml as shown below. Note the attribute name ‘id’ with value ‘1’ (see line 1 below)

Create TestReadAttribute 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 read of attribute for an XML element is shown below.

Download Source Code for this Program

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Bitnami