Woodstox : Coalesce CDATA

Overview This article demonstrates how to optionally coalesce CData content using Woodstox StAX parser. This program shall parse the same XML document twice: once without coalescing and once with coalescing. Create employee.xml as shown below. Note that the name of the employee is mentioned within a CDATA section (see lines 4-6 below). Create TestCoalesceCData as … Read more

Woodstox : Verify Empty Element Content

Overview This article demonstrates how to verify whether an element is empty or not using Woodstox StAX parser. Create employee.xml as shown below. Note that the element ‘address’ is empty. Create TestVerifyEmptyElement class as shown below. Note that start element is obtained by using the StAX API (see lines 20-26 below). Verify that the ‘address’ … Read more

Woodstox : Read Namespace Of XML Start Element

Overview This article demonstrates how to read namespace related information using Woodstox 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 class as shown below. Note that start element is obtained by using the … Read more

Woodstox : Read Attribute Of XML Element

Overview This article demonstrates how to read the attribute in an XML element using Woodstox. Create employee.xml as shown below. Note the attribute ‘id’ for the element ’employee’ (see line 1 below). Create TestReadAttribute class as shown below. Note that start element is obtained by using the StAX API (see lines 20-28 below). The following … Read more

Woodstox : Peek to Next Element

Overview Woodstox provides a feature to peek into the next XML element from the current XML element. This is achieved by using XMLEventReader.peek() method. This sample program demonstrates how to peek into the next XML element. Create the employee.xml as shown below. Note that there are three XML elements: start element ’employee’ character content ‘some … Read more

java-xml-woodstox-stax-replace-entity-reference

Overview XML documents can refer to entities defined in DTD. Woodstox provides support for replacing the entity reference with its corresponding value. The following program explores Woodstox’ feature of replacing entity references. Create the employee.dtd as shown below. In particular, note that the entity ‘commonAddress’ is defined with corresponding value ‘Beth Street, Cathy County, Dessert … Read more

Basic StAX Parsing Using Woodstox

Overview Woodstox provides excellent support for StAX (Streaming API for XML) parsing. Streaming API is used to parse large XML documents in a performance efficient manner. StAX compliant parsers do not load the entire XML document in memory but use a ‘Pull Model’ to load sections of document and parse it. Woodstox is compliant with … Read more

Woodstox : Steps In Loading of Woodstox Classes

Overview Woodstox classes are loaded using javax.xml.stream.XMLInputFactory.newInstance() . The steps involved in loading of Woodstox classes is explained below: javax.xml.stream.XMLInputFactory.newInstance() is called by client code The file ‘META-INF/services/javax.xml.stream.XMLInputFactory’ is searched in the current classpath As the current classpath contains woodstox-core-asl-4.2.0.jar, the file ‘META-INF/services/javax.xml.stream.XMLInputFactory’ is found as shown below The contents of ‘META-INF/services/javax.xml.stream.XMLInputFactory’ (as shown below) … Read more

Java XML: Woodstox Introduction

Overview Woodstox is a very powerful toolkit for XML processing.Its main features are as follows: Namespace aware StAX (Streaming API for XML) compliant (JSR-173) processor Support for DTD, RelaxNG and W3C Validations Support for both XML parsing and XML creation SAX (Simple API for XML) parsing and validation High performance processor with excellant error handling … Read more

Java API for XML (JAXP) – XPath

XPath and JAXP XPath is a language for querying XML Documents. Using a certain syntax XPath can retrieve specific node or list of nodes from the XML Document. This tutorial does not explain XPath syntax but shows how to use JAXP to implement XPath querying. The Steps for XPath querying are: Obtain the XPath class … Read more