The LexicalHandler Interface

This extension interface is new in SAX2. It's in the org.xml.sax.ext package, which means among other things that it is optional and isn't supported by all SAX APIs and layers, such as DefaultHandler. However, any SAX2 parser that can be bootstrapped with JAXP supports this interface. Parsers that support LexicalHandler expose comment text and the boundaries of CDATA sections, DTDs, and most parsed entities. There is no setLexicalHandler() method; bind these handlers to parsers like this:

XMLReader producer = ...; LexicalHandler handler = ...; producer.setProperty ("http://xml.org/sax/properties/lexical-handler", handler); // throws SAXNotSupportedException if parameter isn't a LexicalHandler // throws SAXNotRecognizedException if parser doesn't support it. 

The information this exposes is needed for applications that need more in the way of "round-tripping" support than the SAX2 core allows. That is, less of the information read by parsers will be completely discarded. The application needs SAX to provide more complete support for the XML Infoset (or for the XPath data model). To completely support DOM, XPath, or XSLT on top of a SAX2 parser, this interface is as necessary as the namespaces exposed in the SAX2 ContentHandler and Attributes interfaces. The downside is that much of this information is in the category of information applications shouldn't want to deal with. Be careful how you use these callbacks; don't assume that just because the information is available, you should use it.

LexicalHandler has the following methods: