Save This Page
Home » dom4j-1.6.1 » org.dom4j.io » [javadoc | source]
org.dom4j.io
public class: SAXReader [javadoc | source]
java.lang.Object
   org.dom4j.io.SAXReader

Direct Known Subclasses:
    LNSAXReader, SAXModifyReader

SAXReader creates a DOM4J tree from SAX parsing events.

The actual SAX parser that is used by this class is configurable so you can use your favourite SAX parser if you wish. DOM4J comes configured with its own SAX parser so you do not need to worry about configuring the SAX parser.

To explicitly configure the SAX parser that is used via Java code you can use a constructor or use the #setXMLReader(XMLReader) or #setXMLReaderClassName(String) methods.

If the parser is not specified explicitly then the standard SAX policy of using the org.xml.sax.driver system property is used to determine the implementation class of XMLReader .

If the org.xml.sax.driver system property is not defined then JAXP is used via reflection (so that DOM4J is not explicitly dependent on the JAXP classes) to load the JAXP configured SAXParser. If there is any error creating a JAXP SAXParser an informational message is output and then the default (Aelfred) SAX parser is used instead.

If you are trying to use JAXP to explicitly set your SAX parser and are experiencing problems, you can turn on verbose error reporting by defining the system property org.dom4j.verbose to be "true" which will output a more detailed description of why JAXP could not find a SAX parser

For more information on JAXP please go to Sun's Java & XML site

Nested Class Summary:
protected static class  SAXReader.SAXEntityResolver   
Constructor:
 public SAXReader() 
 public SAXReader(boolean validating) 
 public SAXReader(DocumentFactory factory) 
 public SAXReader(XMLReader xmlReader) 
 public SAXReader(String xmlReaderClassName) throws SAXException 
 public SAXReader(DocumentFactory factory,
    boolean validating) 
 public SAXReader(XMLReader xmlReader,
    boolean validating) 
 public SAXReader(String xmlReaderClassName,
    boolean validating) throws SAXException 
Method from org.dom4j.io.SAXReader Summary:
addHandler,   configureReader,   createContentHandler,   createDefaultEntityResolver,   createXMLReader,   getDispatchHandler,   getDocumentFactory,   getEncoding,   getEntityResolver,   getErrorHandler,   getXMLFilter,   getXMLReader,   installXMLFilter,   isIgnoreComments,   isIncludeExternalDTDDeclarations,   isIncludeInternalDTDDeclarations,   isMergeAdjacentText,   isStringInternEnabled,   isStripWhitespaceText,   isValidating,   read,   read,   read,   read,   read,   read,   read,   read,   removeHandler,   resetHandlers,   setDefaultHandler,   setDispatchHandler,   setDocumentFactory,   setEncoding,   setEntityResolver,   setErrorHandler,   setFeature,   setIgnoreComments,   setIncludeExternalDTDDeclarations,   setIncludeInternalDTDDeclarations,   setMergeAdjacentText,   setProperty,   setStringInternEnabled,   setStripWhitespaceText,   setValidation,   setXMLFilter,   setXMLReader,   setXMLReaderClassName
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.dom4j.io.SAXReader Detail:
 public  void addHandler(String path,
    ElementHandler handler) 
    Adds the ElementHandler to be called when the specified path is encounted.
 protected  void configureReader(XMLReader reader,
    DefaultHandler handler) throws DocumentException 
    Configures the XMLReader before use
 protected SAXContentHandler createContentHandler(XMLReader reader) 
    Factory Method to allow user derived SAXContentHandler objects to be used
 protected EntityResolver createDefaultEntityResolver(String systemId) 
 protected XMLReader createXMLReader() throws SAXException 
    Factory Method to allow alternate methods of creating and configuring XMLReader objects
 protected DispatchHandler getDispatchHandler() 
 public DocumentFactory getDocumentFactory() 
    DOCUMENT ME!
 public String getEncoding() 
    Returns encoding used for InputSource (null means system default encoding)
 public EntityResolver getEntityResolver() 
    Returns the current entity resolver used to resolve entities
 public ErrorHandler getErrorHandler() 
    DOCUMENT ME!
 public XMLFilter getXMLFilter() 
    Returns the SAX filter being used to filter SAX events.
 public XMLReader getXMLReader() throws SAXException 
    DOCUMENT ME!
 protected XMLReader installXMLFilter(XMLReader reader) 
    Installs any XMLFilter objects required to allow the SAX event stream to be filtered and preprocessed before it gets to dom4j.
 public boolean isIgnoreComments() 
    Returns whether we should ignore comments or not.
 public boolean isIncludeExternalDTDDeclarations() 
    DOCUMENT ME!
 public boolean isIncludeInternalDTDDeclarations() 
    DOCUMENT ME!
 public boolean isMergeAdjacentText() 
    Returns whether adjacent text nodes should be merged together.
 public boolean isStringInternEnabled() 
    Sets whether String interning is enabled or disabled for element & attribute names and namespace URIs. This proprety is enabled by default.
 public boolean isStripWhitespaceText() 
    Sets whether whitespace between element start and end tags should be ignored
 public boolean isValidating() 
    DOCUMENT ME!
 public Document read(File file) throws DocumentException 

    Reads a Document from the given File

 public Document read(URL url) throws DocumentException 

    Reads a Document from the given URL using SAX

 public Document read(String systemId) throws DocumentException 

    Reads a Document from the given URL or filename using SAX.

    If the systemId contains a ':' character then it is assumed to be a URL otherwise its assumed to be a file name. If you want finer grained control over this mechansim then please explicitly pass in either a URL or a File instance instead of a String to denote the source of the document.

 public Document read(InputStream in) throws DocumentException 

    Reads a Document from the given stream using SAX

 public Document read(Reader reader) throws DocumentException 

    Reads a Document from the given Reader using SAX

 public Document read(InputSource in) throws DocumentException 

    Reads a Document from the given InputSource using SAX

 public Document read(InputStream in,
    String systemId) throws DocumentException 

    Reads a Document from the given stream using SAX

 public Document read(Reader reader,
    String systemId) throws DocumentException 

    Reads a Document from the given Reader using SAX

 public  void removeHandler(String path) 
    Removes the ElementHandler from the event based processor, for the specified path.
 public  void resetHandlers() 
    This method clears out all the existing handlers and default handler setting things back as if no handler existed. Useful when reusing an object instance.
 public  void setDefaultHandler(ElementHandler handler) 
    When multiple ElementHandler instances have been registered, this will set a default ElementHandler to be called for any path which does NOT have a handler registered.
 protected  void setDispatchHandler(DispatchHandler dispatchHandler) 
 public  void setDocumentFactory(DocumentFactory documentFactory) 

    This sets the DocumentFactory used to create new documents. This method allows the building of custom DOM4J tree objects to be implemented easily using a custom derivation of DocumentFactory

 public  void setEncoding(String encoding) 
    Sets encoding used for InputSource (null means system default encoding)
 public  void setEntityResolver(EntityResolver entityResolver) 
    Sets the entity resolver used to resolve entities.
 public  void setErrorHandler(ErrorHandler errorHandler) 
    Sets the ErrorHandler used by the SAX XMLReader.
 public  void setFeature(String name,
    boolean value) throws SAXException 
    Sets a SAX feature on the underlying SAX parser. This can be useful to set parser-specific features. Though use this method with caution as it has the possibility of breaking the standard behaviour. An alternative to calling this method is to correctly configure an XMLReader object instance and call the #setXMLReader(XMLReader) method
 public  void setIgnoreComments(boolean ignoreComments) 
    Sets whether we should ignore comments or not.
 public  void setIncludeExternalDTDDeclarations(boolean include) 
    Sets whether DTD external declarations should be expanded into the DocumentType object or not.
 public  void setIncludeInternalDTDDeclarations(boolean include) 
    Sets whether internal DTD declarations should be expanded into the DocumentType object or not.
 public  void setMergeAdjacentText(boolean mergeAdjacentText) 
    Sets whether or not adjacent text nodes should be merged together when parsing.
 public  void setProperty(String name,
    Object value) throws SAXException 
    Allows a SAX property to be set on the underlying SAX parser. This can be useful to set parser-specific properties such as the location of schema or DTD resources. Though use this method with caution as it has the possibility of breaking the standard behaviour. An alternative to calling this method is to correctly configure an XMLReader object instance and call the #setXMLReader(XMLReader) method
 public  void setStringInternEnabled(boolean stringInternEnabled) 
    Sets whether String interning is enabled or disabled for element & attribute names and namespace URIs
 public  void setStripWhitespaceText(boolean stripWhitespaceText) 
    Sets whether whitespace between element start and end tags should be ignored.
 public  void setValidation(boolean validation) 
    Sets the validation mode.
 public  void setXMLFilter(XMLFilter filter) 
    Sets the SAX filter to be used when filtering SAX events
 public  void setXMLReader(XMLReader reader) 
    Sets the XMLReader used to parse SAX events
 public  void setXMLReaderClassName(String xmlReaderClassName) throws SAXException 
    Sets the class name of the XMLReader to be used to parse SAX events.