Appendix B. Parser Reference



XMLReader is the main interface to the parser. The application must create an instance of XMLReader and register the appropriate event handlers with it.

Registering Event Handlers

The following methods are used to register event handlers:

  • void setContentHandler(ContentHandler handler) / ContentHandler getContentHandler() ”Register a ContentHandler .

  • void setDTDHandler(DTDHandler handler) / DTDHandler getDTDHandler() ”Register a DTDHandler .

  • void setErrorHandler(ErrorHandler handler) / ErrorHandler getErrorHandler() ”Register an ErrorHandler .

  • void setEntityResolver(EntityResolver resolver) / EntityResolver getEntityResolver() ”Register an EntityResolver .


The following are the two parse() methods:

  • void parse(InputSource input) ”Parses an XML document identified by an InputSource .

  • void parse(String systemId) ”Parses an XML document from a system identifier (typically a URI).

Features and Properties

XMLReader also offers methods to parsing options:

  • void setFeature(String name ,boolean value) / boolean getFeature(String name) ”Set a feature; a feature has a Boolean value and is identified by a name.

  • void setProperty(String name,Object value) / Object getProperty(String name) ”Set a property; a property has an object value and is identified by a name.

Similar to namespaces, feature and property names are URIs. This limits the risk that two developers would define conflicting features or properties with the same name.

Parser developers are free to implement their own features and properties. The SAX2 specification defines the following standard features. The first two features are mandatory for SAX2 parsers:

  • ”When true, the parser must process namespaces. When false, the parser is free to process them as it sees fit.

  • ”When true, the parser must report the original prefixed names and attributes used for namespace declarations.

  • ”when true , all names are internalized strings. When false, strings are internalized as the parser sees fit.

  • ”Turns on and off validation errors.

  • ” Controls the inclusion of external general entities.

  • ” Controls the inclusion of external parameter entities.


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142 © 2008-2017.
If you may any questions please contact us: