A lesser used interface, DeclHandler is another of the extended SAX interfaces. This interface defines methods that receive notification of specific events within a DTD, such as element and attribute declarations. This is another item only good for very specific cases; again, XML editors and components that must know the exact lexical structure of documents and their DTDs come to mind. Iím not going to show you an example of using the DeclHandler ; at this point you know more than youíll probably ever need to about handling callback methods. Instead, Iíll just give you a look at the interface, shown in Figure 4-6.
The DeclHandler interface is fairly self-explanatory. The first two methods handle the <!ELEMENT> and <!ATTLIST> constructs. The third, externalEntityDecl() , reports entity declarations (through <!ENTITY> ) that refer to external resources. The final method, internalEntityDecl() , reports entities defined inline. Thatís all there is to it.
Figure 4-6. The Dec1Handler interface isn't used often, but it's a real boon if you need to write code that deals directly with DTDs
Attributes2, Locator2, and EntityResolver2
SAX provides three other interesting interfaces in org.xml.sax.ext: Attributes2 , Locator2 , and EntityResolver2 . These all extend their respective core interfaces from org.xml.sax ( Attributes , Locator , and EntityResolver ), and class diagrams are shown for all three in Figure 4-7.
Figure 4-7. The Attributes2, EntityResolver2, and Locator2 interfaces
These interfaces provide additional information for use in parsing, ranging from whether an attribute was specified in a DTD to the encoding of an XML document (pulled from the XML declaration). You can find out if your parser supports and uses these extensions via the getFeature() method:
// Check for Attributes2 usag e featureURI = "http://xml.org/sax/features/use-attributes2"; jTreeHandler.setUsingAttributes2(reader.getFeature(featureURI));
// Check for Locator2 usage featureURI = "http://xml.org/sax/features/use-locator2"; jTreeHandler.setUsingLocator2(reader.getFeature(featureURI));
These and all other SAX-standard feature and property URIs are detailed in the Appendix.