SAX Extensions Using Aalto


As the name suggests, SAX extensions are an extension to the parsing capabilities of a SAX parser. SAX extensions provide additional capabilities to parse comments, DTD element, CData sections, etc.

Additionally, there are several feature related flags (e.g.
, etc.) which can be set. Please refer to the
package summary
for more details.

Create employee.xml as shown below.

It contains DTD reference (see line 1 below), comment (see line 2 below) and CData section (see lines 7-9 below).

Create employee.dtd as shown below.

This DTD is referred to in line 1 in employee.xml shown above.

Create TestSaxParsingUsingSaxExtensions class as shown below.

Note that
is referred (see line 23 below) to signify that SAX extension API is used.

Override the ‘comment()’,’startDTD()’,’startCDATA()’,’endCDATA()’

Set the lexical handler (see line 55 below). According to javadoc documentation, Lexical handlers provide lexical information about an XML document, such as comments and CDATA section boundaries. The events in the lexical handler apply to the entire document, not just to the document element, and all lexical handler events must appear between the content handler’s startDocument and endDocument events.

Finally, pass the
class to the parser (see line 58 below).

The output of the program demonstrating SAX extensions using Aalto is shown below.

Download Source Code for this Program

Leave a Comment