Aalto StAX Parsing: Error Handling

Overview This article demonstrates how to handle parser related errors using Aalto StAX parser. Create employee.xml as shown below. Note that the ‘salary’ element is not properly closed (see line 4 below). Create TestErrorHandling as shown below. Catch the WFCException (see line 39 below)) which is short for ‘Well-Formedness Constraint violation’ exception. The output of … Read more

Aalto StAX Parsing: Reading Namespace

Overview This article demonstrates the how to read namespace related information using Aalto StAX parser. Create employee.xml as shown below. Note the namespace URI ‘http://www.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 … Read more

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 … Read more

Aalto StAX Parsing: Peek To Next Element

Overview Aalto provides a feature to peek into the next XML element from the current XML element. This is achieved by using XMLEventReader.peek() method. Note that according JSR-173 specification, XmlEventReader.peek() method returns the next element but does not take it off the stream. This sample program demonstrates how to peek into the next XML element. … Read more

Aalto StAX Parsing: Entity Reference

Overview This article demonstrates how to parse entity references using Aalto StAX parser. Note that as of Aalto version 0.9.6, replacing of entity references is not supported. Parsing shall only return the entity reference itself. Create employee.xml as shown below. Note that an entity reference ‘entity-reference1’ is used for address element (see line 5 below) … Read more

Aalto StAX Parsing: Empty Element

Overview This article demonstrates how to to verify whether an element is empty or not using Aalto StAX parser. Create employee.xml as shown below. Keep the address element empty (see line 4 below). Create TestVerifyEmptyElement class as shown below. For the ‘address’ element (see line 21 below), use XMLStreamReader2.isEmptyElement() method to verify whether the element … Read more

Aalto StAX Parsing: Document Type

Overview This sample program demonstrates the parsing of documment type within XML using Aalto StAX parser. Create employee.xml as shown below. Note the doc type element with prefix name ’employee’, public id ‘-//STUDYTRAILS//DTD 4.1//EN’ and system id ’employee.dtd’ (see line 1 below). Create TestDocType as shown below. For the event type XMLEvent.DTD (see line 22 … Read more

Aalto StAX Parsing: Get Version and Encoding

Overview This sample program demonstrates how to access the XML document version and encoding information. Create employee.xml as shown below. Note the xml version number and encoding information (see line 1 below) Create TestVersionAndEncoding class as shown below. For any element, in this case ’employee’ (see line 22 below), get the version and encoding information … Read more

Aalto StAX Parsing: Coalescing CData

Overview This article demonstrates how to optionally coalesce CData content using Aalto StAX parser. This program shall parse the same XML document twice: once without coalescing and once with coalescing and display the output corresponding to each scenario. Create employee.xml as shown below. Note that the name of the employee is mentioned within a CDATA … Read more