The DTDHandler Interface

The last core document handler that SAX provides registers callback methods during the process of reading and parsing an XML document’s DTD. This interface does not define events that take place during the process of validation, but only those that occur during the process of reading the DTD. In fact, in our section on “gotchas” we will look at some of the confusion this distinction often causes. This handler behaves in the same manner as the ContentHandler and ErrorHandler interfaces that we looked at in Chapter 3, defining two callback methods that occur during the parsing process.

As important as XML document validation is, the events involved with reading the DTD document are not very significant. With only two callback methods, and both of those not commonly used, you will probably not find many uses for the DTDHandler interface unless you are writing an XML editor or IDE and need to build or process DTD documents for correct syntax and notation. We will look at the two callback methods provided by SAX here, but will not spend much time on their use, as they are not significant in our use of XML for non-editor type applications. For information on an optional SAX handler that can help in reading further DTD information, refer to the DeclHandler interface in Appendix A, under the org.xml.sax.ext package.

Unparsed Entity Declarations

The first callback method, unparsedEntityDecl( ) , is invoked when a DTD has an entity declaration signifying that the XML ...

Get Java and XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.