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

Java XML – JDOM2 – Filters

JDOM2 has three methods that accepts Filters while obtaining data. The three methods are &ltE extends Content&gt List&ltE&gt getContent(Filter&ltE&gt filter); &ltE extends Content&gt List&ltE&gt removeContent(Filter&ltE&gt filter); &ltE extends Content&gt IteratorIterable&ltE&gt getDescendants(Filter&ltE&gt filter); Filters are also extensively used in the JDOM2 XPath API, especially to ‘coerce the xpath result data in to the generic-typed results’. See … Read more

Java XML – JDOM2 – StAXBuilder

In the previous examples we saw how to bulid a JDOM2 document from w3c Document. We also saw how to build a JDOM2 Document using a SAXBuilder. In this example we look at how to create a JDOM2 document using a StAXEventBuilder or a StAXStreamBuilder. StAXEventBuilder StAXEventBuilder builds a JDOM2 document using a StAX based … Read more

Java XML – JDOM2 – DOMBuilder

Buliding JDOM2 documents from w3c DOM JDOM2 provides a DOMBuilder that can be used to build a JDOM2 Document from a org.w3c.dom.Document. If there are namespace declarations in the xml document then make sure that while parsing the XML document the setNamespaceAware method of the DocumentBuilderFactory is set to true. Before we look at an … Read more

Java XML – JDOM2 – SAXBuilder

The Plot SAXBuilder provides methods to build JDOM2 Documents using a third party SAX Parser. It has three parts A SAX Parser to parse the XML document. The default Parser is JAXP. A SAX Handler to handle SAX events. A JDOM2 Factory to build the JDOM2 Document This tutorial introduces the various classes that form … Read more