Appendix B. Parser Reference

   

XMLReader

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 .

Parsing

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:

  • http://xml.org/sax/features/namespaces ”When true, the parser must process namespaces. When false, the parser is free to process them as it sees fit.

  • http://xml.org/sax/features/namespace-prefixes ”When true, the parser must report the original prefixed names and attributes used for namespace declarations.

  • http://xml.org/sax/features/string-interning ”when true , all names are internalized strings. When false, strings are internalized as the parser sees fit.

  • http://xml.org/sax/features/validation ”Turns on and off validation errors.

  • http://xml.org/sax/features/external-general-entities ” Controls the inclusion of external general entities.

  • http://xml.org/sax/features/external-parameter-entities ” Controls the inclusion of external parameter entities.

   


Applied XML Solutions
Applied XML Solutions
ISBN: 0672320541
EAN: 2147483647
Year: 1999
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net