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

Aalto: Basic StAX Parsing Using Aalto

Overview Aalto provides JSR-173 compliant StAX (Streaming API for XML) parsing. The key classes involved in StAX parsing are XMLInputFactory2 , XMLStreamReader2 and XMLEvent . The following sample program demonstrates how to perform basic StAX parsing Create employee.xml as shown below. It contains employee related information like id, name and salary (see lines 2-4 below) … Read more

Java XML: Aalto Introduction

Overview Aalto is a toolkit for XML processing. It supports the following features: Namespace aware StAX (Streaming API for XML) compliant (JSR-173) processor Support for both XML parsing and XML creation SAX (Simple API for XML) parsing High performance processor with excellant error handling support In particular, the main differentiator of Aalto in comparison with … Read more

Java XML – JDOM2 – XPath

Xpath is a query language specification that is used to query an XML path. It provides a language that helps in retrieving specific nodes of an XML document using a query syntax. This tutorial does not explain XPath and assumes that the user is aware of XPath. What we explain here is how to use … Read more

Java XML – JDOM2 – XSLTransformation

JDOM2 has classes that perform XSL transformation of the JDOM2 document. The input to the transformation is the JDOM2 document and an XML stylesheet and the output is whatever transformation the stylesheet specifies. In the example below we look at JDOM2 to do HTML transformation. By default, JDOM2 uses the JAXP TrAX classes for transformation. … Read more