Entities, Handlers and SAX - Notations and Unparsed Entities (Page 2 of 4 )
After a rather extensive look at EntityResolver, Iím going to cruise through DTDHandler (also in org.xml.sax ). In almost nine years of extensive SAX and XML programming, Iíve used this interface only onceóin writing JDOM (covered in Chapter 9)óand even then, it was a rather obscure case. Still, if you work with unparsed entities often, are into parser internals, or just want to get into every nook and cranny of the SAX API, then you need to know about DTDHandler . The interface is shown in all its simplicity in Figure 4-4.
Figure 4-4. This handler is concerned with the declartion of certain XML types, rather than the actual content of those entities (if and when they are resolved)
The DTDHandler interface allows you to receive notification when a reader encounters an unparsed entity or notation declaration. Of course, both of these events occur in DTDs, not XML documents, which is why this is called DTDHandler . The two methods listed in Figure 4-4 do exactly what you would expect. The first reports a notation declaration, including its name, public ID, and system ID. Remember the NOTATION structure in DTDs? (Flip back to Chapter 2 if youíre unclear.)
<!NOTATION jpeg SYSTEM "images/jpeg">
The second method provides information about an unparsed entity declaration, which looks as follows:
<!ENTITY stars_logo SYSTEM "http://www.nhl.com/img/team/dal38.gif" NDATA jpeg>
In both cases, you can take action at these occurrences if you create an implementa tion of DTDHandler and register it with your reader through the XMLReader ís setDTDHandler() method. This is generally useful when writing low-level applications that must either reproduce XML content (such as an XML editor), or when you want to build up some Java representation of a DTDís constraints (such as in a data binding implementation). In most other situations, it isnít something you will need very often.