Name

SAXParserFactory

Synopsis

This class is a factory for SAXParser objects. Obtain a SAXParserFactory by calling the newInstance( ) method which instantiates the default SAXParserFactory subclass provided with your Java implementation, or instantiates some other SAXParserFactory that has been “plugged in”.

Once you have a SAXParserFactory object, you can use setValidating( ) and setNamespaceAware( ) to specify whether the parsers it creates will be validating parsers or not and whether they will know how to handle XML namespaces. You may also call setFeature( ) to set a feature of the underlying parser implementation. See http://www.saxproject.org for the names of standard parser features that can be enabled and disabled with this method. In Java 5.0, call setXIncludeAware( ) to specify that created parsers will recognize XInclude markup. Use setSchema( ) to specify a W3C XML Schema against which parsers should validate the document.

Once you have created and configured your factory object, simply call newSAXParser( ) to create a SAXParser object. Note that SAXParserFactory implementations are not typically threadsafe.

The javax.xml.parsers package allows parser implementations to be “plugged in”. This pluggability is provided by the getInstance( ) method, which follows the following steps to determine which SAXBuilderFactory subclass to use:

  • If the javax.xml.parsers.SAXParserFactory system property is defined, then the class specified by that property is used.

  • Otherwise, if the ...

Get Java in a Nutshell, 5th 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.