Detailed Asynchronous StAX Parsing Using Aalto: Parsing Comments, Processing Instructions, CData and Entity References

Overview

In the
earlier article
we explored basic asynchronous StAX parsing using Aalto.

In this article we shall see how Aalto’s asynchronous StAX parsing can be used to parse XML comments, processing instructions, CData and entity references.

Create employee.xml as shown below. It contains comment, processing instruction, CDATA and entity references (see lines 1,3,7-9 and 11 respectively)

Create AsyncReaderWrapper class as shown below.

See
this article
for details on usage of this class.

Create TestAsyncParsingDetailed as shown below.

It uses
AsyncReaderWrapper
(described above) for handling low level buffer management for asynchronous parsing.

  • Comments are handled using XMLEvent.COMMENT event (see lines 35-37 below)
  • Processing Instructions are handled using XMLEvent.PROCESSING_INSTRUCTION event (see lines 38-41 below)
  • CDATA is handled using XMLEvent.CDATA event (see lines 48-50 below)
  • Entity Reference is handled using XMLEvent.ENTITY_REFERENCE event (see lines 51-53 below)

The output of the program demonstrating detailed parsing of XML comments, processing instructions, CData and entity references is shown below.

Download Source Code for this Program

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top
Bitnami