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

Java XML – JDOM2 – Outputter

Introduction In the earlier tutorials we looked at how to create a JDOM2 document from SAX ,DOM and StAX. In this tutorial we learn how to output JDOM2 as XML, DOM, SAX, StAXEvent and StaxStream. Lets look at the important classes Important Classes XMLOutputter – This is probably the most useful outputter. It outputs the … Read more

Java XML – JDOM2 – Namespaces

JDOM2 handles namespaces very well. However, there are three areas where confusion may arise while using namespaces. In this tutorial we look at them. Creating new elements While creating new elements in JDOM2, it is possible to pass the namespace to which the element should belong. However, the namespace only applies to the Element and … Read more