Name

The DeclHandler Interface

Synopsis

DeclHandler is a callback interface that provides information about the ELEMENT, ATTLIST, and parsed ENTITY declarations in the document’s DTD. To configure an XMLReader with a DeclHandler, pass the name http://xml.org/sax/properties/DeclHandler and an instance of the handler to the reader’s setProperty( ) method:

try {
  parser.setProperty(
   "http://xml.org/sax/properties/DeclHandler",
    new YourDeclHandlerImplementationClass(  ));
}
catch(SAXException ex) {
  System.out.println("This parser does not provide declarations.");
}

If the parser does not provide declaration events, it throws a SAXNotRecognizedException. If the parser cannot install a DeclHandler at this moment (generally because it’s in the middle of parsing a document), then it throws a SAXNotSupportedException. If it doesn’t throw one of these exceptions, it will call back to the methods in your DeclHandler as it parses the DTD:

package org.xml.sax.ext;
     
public interface DeclHandler {
     
  public void elementDecl(String name, String model) throws SAXException;
  public void attributeDecl(String elementName, String attributeName,
   String type, String defaultValue, String value) throws SAXException;
  public void internalEntityDecl(String name, String value)
   throws SAXException;
  public void externalEntityDecl(String name, String publicID,
   String systemID) throws SAXException;
     
}

Get XML in a Nutshell, 3rd Edition 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.