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
| Modifier and Type | Class and Description |
|---|---|
| protected static class |
| Modifier and Type | Field and Description |
|---|---|
| private DispatchHandler | dispatchHandler
DispatchHandler to call when each |
| private String | encoding
Encoding of InputSource - null means system default encoding |
| private EntityResolver | entityResolver
The entity resolver |
| private ErrorHandler | errorHandler
ErrorHandler class to use |
| private DocumentFactory | factory
|
| private boolean | ignoreComments
Should we ignore comments |
| private boolean | includeExternalDTDDeclarations
Should external DTD declarations be expanded into a List in the DTD |
| private boolean | includeInternalDTDDeclarations
Should internal DTD declarations be expanded into a List in the DTD |
| private boolean | mergeAdjacentText
Whether adjacent text nodes should be merged |
| private static final String | |
| private static final String | |
| private static final String | |
| private static final String | |
| private boolean | stringInternEnabled
Should element & attribute names and namespace URIs be interned? |
| private boolean | stripWhitespaceText
Holds value of property stripWhitespaceText. |
| private boolean | validating
Whether validation should occur |
| private XMLFilter | xmlFilter
The SAX filter used to filter SAX events |
| private XMLReader | xmlReader
|
| Access | Constructor and Description |
|---|---|
| public | SAXReader()
This method internally calls |
| public | SAXReader(boolean validating)
This method internally calls |
| public | SAXReader(DocumentFactory factory)
This method internally calls |
| public | SAXReader(DocumentFactory factory, boolean validating)
This method internally calls |
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addHandler(String
is the path to be handled path, ElementHandler is the handler)ElementHandler to be called by the event
based processor.Adds the |
| protected void | configureReader(XMLReader
DOCUMENT ME! reader, DefaultHandler DOCUMENT ME! handler)Configures the XMLReader before use |
| protected SAXContentHandler | Returns: DOCUMENT ME!DOCUMENT ME! reader)Factory Method to allow user derived SAXContentHandler objects to be used |
| public static SAXReader | |
| protected EntityResolver | |
| protected XMLReader | Returns: DOCUMENT ME!Factory Method to allow alternate methods of creating and configuring XMLReader objects |
| protected DispatchHandler | |
| public DocumentFactory | |
| public String | Returns: encoding used for InputSourceReturns encoding used for InputSource (null means system default encoding) |
| public EntityResolver | Returns: DOCUMENT ME!Returns the current entity resolver used to resolve entities |
| public ErrorHandler | |
| public XMLFilter | Returns: the SAX filter being used or null if no SAX filter is installedReturns the SAX filter being used to filter SAX events. |
| public XMLReader | |
| protected XMLReader | Returns: the new XMLFilter if applicable or the original XMLReader if no filter is being used.DOCUMENT ME! reader)Installs any XMLFilter objects required to allow the SAX event stream to be filtered and preprocessed before it gets to dom4j. |
| public boolean | |
| public boolean | Returns: whether external DTD declarations should be expanded into the DocumentType object or not.DOCUMENT ME! |
| public boolean | Returns: whether internal DTD declarations should be expanded into the DocumentType object or not.DOCUMENT ME! |
| public boolean | Returns: Value of property mergeAdjacentText.Returns whether adjacent text nodes should be merged together. |
| public boolean | Returns: DOCUMENT ME!Sets whether String interning is enabled or disabled for element & attribute names and namespace URIs. |
| public boolean | Returns: Value of property stripWhitespaceText.Sets whether whitespace between element start and end tags should be ignored |
| public boolean | Returns: the validation mode, true if validating will be done otherwise false.DOCUMENT ME! |
| public Document | |
| public Document | |
| public Document | |
| public Document | Returns: the newly created Document instanceInputStream to read from.Reads a Document from the given stream using SAX |
| public Document | |
| public Document | Returns: the newly created Document instanceInputStream to read from.is the URI for the input systemId)Reads a Document from the given stream using SAX |
| public Document | |
| public Document | Returns: the newly created Document instanceInputSource to read from.
Reads a Document from the given |
| public void | removeHandler(String
is the path to remove the path)ElementHandler for.Removes the |
| public void | resetHandlers()
This method clears out all the existing handlers and default handler setting things back as if no handler existed. |
| public void | setDefaultHandler(ElementHandler
is the handler)ElementHandler to be called by the event
based processor.When multiple |
| protected void | |
| public void | setDocumentFactory(DocumentFactory
DocumentFactory used to create DOM4J objects
This sets the |
| public void | setEncoding(String
is encoding used for InputSource encoding)Sets encoding used for InputSource (null means system default encoding) |
| public void | setEntityResolver(EntityResolver
DOCUMENT ME! entityResolver)Sets the entity resolver used to resolve entities. |
| public void | setErrorHandler(ErrorHandler
is the errorHandler)ErrorHandler used by SAXSets the |
| public void | setFeature(String
is the SAX feature name name, boolean is the value of the SAX feature value)Sets a SAX feature on the underlying SAX parser. |
| public void | setIgnoreComments(boolean
whether we should ignore comments or not. ignoreComments)Sets whether we should ignore comments or not. |
| public void | setIncludeExternalDTDDeclarations(boolean
whether or not DTD declarations should be expanded and
included into the DocumentType object. include)Sets whether DTD external declarations should be expanded into the DocumentType object or not. |
| public void | setIncludeInternalDTDDeclarations(boolean
whether or not DTD declarations should be expanded and
included into the DocumentType object. include)Sets whether internal DTD declarations should be expanded into the DocumentType object or not. |
| public void | setMergeAdjacentText(boolean
New value of property mergeAdjacentText. mergeAdjacentText)Sets whether or not adjacent text nodes should be merged together when parsing. |
| public void | setProperty(String
is the SAX property name name, Object is the value of the SAX property value)Allows a SAX property to be set on the underlying SAX parser. |
| public void | setStringInternEnabled(boolean
DOCUMENT ME! stringInternEnabled)Sets whether String interning is enabled or disabled for element & attribute names and namespace URIs |
| public void | setStripWhitespaceText(boolean
New value of property stripWhitespaceText. stripWhitespaceText)Sets whether whitespace between element start and end tags should be ignored. |
| public void | setValidation(boolean
indicates whether or not validation should occur. validation)Sets the validation mode. |
| public void | setXMLFilter(XMLFilter
is the SAX filter to use or null to disable filtering filter)Sets the SAX filter to be used when filtering SAX events |
| public void | setXMLReader(XMLReader
is the reader)XMLReader to parse SAX eventsSets the |
| public void | setXMLReaderClassName(String
is the class name of the xmlReaderClassName)XMLReader to parse SAX
eventsSets the class name of the |
| dispatchHandler | back to summary |
|---|---|
| private DispatchHandler dispatchHandler DispatchHandler to call when each | |
| encoding | back to summary |
|---|---|
| private String encoding Encoding of InputSource - null means system default encoding | |
| entityResolver | back to summary |
|---|---|
| private EntityResolver entityResolver The entity resolver | |
| errorHandler | back to summary |
|---|---|
| private ErrorHandler errorHandler ErrorHandler class to use | |
| factory | back to summary |
|---|---|
| private DocumentFactory factory
| |
| ignoreComments | back to summary |
|---|---|
| private boolean ignoreComments Should we ignore comments | |
| includeExternalDTDDeclarations | back to summary |
|---|---|
| private boolean includeExternalDTDDeclarations Should external DTD declarations be expanded into a List in the DTD | |
| includeInternalDTDDeclarations | back to summary |
|---|---|
| private boolean includeInternalDTDDeclarations Should internal DTD declarations be expanded into a List in the DTD | |
| mergeAdjacentText | back to summary |
|---|---|
| private boolean mergeAdjacentText Whether adjacent text nodes should be merged | |
| SAX_DECL_HANDLER | back to summary |
|---|---|
| private static final String SAX_DECL_HANDLER | |
| SAX_LEXICAL_HANDLER | back to summary |
|---|---|
| private static final String SAX_LEXICAL_HANDLER | |
| SAX_LEXICALHANDLER | back to summary |
|---|---|
| private static final String SAX_LEXICALHANDLER | |
| SAX_STRING_INTERNING | back to summary |
|---|---|
| private static final String SAX_STRING_INTERNING | |
| stringInternEnabled | back to summary |
|---|---|
| private boolean stringInternEnabled Should element & attribute names and namespace URIs be interned? | |
| stripWhitespaceText | back to summary |
|---|---|
| private boolean stripWhitespaceText Holds value of property stripWhitespaceText. | |
| validating | back to summary |
|---|---|
| private boolean validating Whether validation should occur | |
| xmlFilter | back to summary |
|---|---|
| private XMLFilter xmlFilter The SAX filter used to filter SAX events
| |
| xmlReader | back to summary |
|---|---|
| private XMLReader xmlReader
| |
| SAXReader | back to summary |
|---|---|
| public SAXReader() This method internally calls
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
| |
| SAXReader | back to summary |
|---|---|
| public SAXReader(boolean validating) This method internally calls
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
| |
| SAXReader | back to summary |
|---|---|
| public SAXReader(DocumentFactory factory) This method internally calls
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
| |
| SAXReader | back to summary |
|---|---|
| public SAXReader(DocumentFactory factory, boolean validating) This method internally calls
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
| |
| SAXReader | back to summary |
|---|---|
| public SAXReader(XMLReader xmlReader) | |
| SAXReader | back to summary |
|---|---|
| public SAXReader(XMLReader xmlReader, boolean validating) | |
| SAXReader | back to summary |
|---|---|
| public SAXReader(String xmlReaderClassName) throws SAXException | |
| SAXReader | back to summary |
|---|---|
| public SAXReader(String xmlReaderClassName, boolean validating) throws SAXException | |
| addHandler | back to summary |
|---|---|
| public void addHandler(String path, ElementHandler handler) Adds the
| |
| configureReader | back to summary |
|---|---|
| protected void configureReader(XMLReader reader, DefaultHandler handler) throws DocumentException Configures the XMLReader before use
| |
| createContentHandler | back to summary |
|---|---|
| protected SAXContentHandler createContentHandler(XMLReader reader) Factory Method to allow user derived SAXContentHandler objects to be used
| |
| createDefault | back to summary |
|---|---|
| public static SAXReader createDefault() | |
| createDefaultEntityResolver | back to summary |
|---|---|
| protected EntityResolver createDefaultEntityResolver(String systemId) | |
| createXMLReader | back to summary |
|---|---|
| protected XMLReader createXMLReader() throws SAXException Factory Method to allow alternate methods of creating and configuring XMLReader objects
| |
| getDispatchHandler | back to summary |
|---|---|
| protected DispatchHandler getDispatchHandler() | |
| getDocumentFactory | back to summary |
|---|---|
| public DocumentFactory getDocumentFactory() DOCUMENT ME!
| |
| getEncoding | back to summary |
|---|---|
| public String getEncoding() Returns encoding used for InputSource (null means system default encoding)
| |
| getEntityResolver | back to summary |
|---|---|
| public EntityResolver getEntityResolver() Returns the current entity resolver used to resolve entities
| |
| getErrorHandler | back to summary |
|---|---|
| public ErrorHandler getErrorHandler() DOCUMENT ME!
| |
| getXMLFilter | back to summary |
|---|---|
| public XMLFilter getXMLFilter() Returns the SAX filter being used to filter SAX events.
| |
| getXMLReader | back to summary |
|---|---|
| public XMLReader getXMLReader() throws SAXException DOCUMENT ME!
| |
| installXMLFilter | back to summary |
|---|---|
| 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. | |
| isIgnoreComments | back to summary |
|---|---|
| public boolean isIgnoreComments() Returns whether we should ignore comments or not.
| |
| isIncludeExternalDTDDeclarations | back to summary |
|---|---|
| public boolean isIncludeExternalDTDDeclarations() DOCUMENT ME!
| |
| isIncludeInternalDTDDeclarations | back to summary |
|---|---|
| public boolean isIncludeInternalDTDDeclarations() DOCUMENT ME!
| |
| isMergeAdjacentText | back to summary |
|---|---|
| public boolean isMergeAdjacentText() Returns whether adjacent text nodes should be merged together.
| |
| isStringInternEnabled | back to summary |
|---|---|
| public boolean isStringInternEnabled() Sets whether String interning is enabled or disabled for element & attribute names and namespace URIs. This proprety is enabled by default.
| |
| isStripWhitespaceText | back to summary |
|---|---|
| public boolean isStripWhitespaceText() Sets whether whitespace between element start and end tags should be ignored
| |
| isValidating | back to summary |
|---|---|
| public boolean isValidating() DOCUMENT ME!
| |
| read | back to summary |
|---|---|
| public Document read(File file) throws DocumentException
Reads a Document from the given
| |
| read | back to summary |
|---|---|
| public Document read(URL url) throws DocumentException
Reads a Document from the given
| |
| read | back to summary |
|---|---|
| public Document read(String systemId) throws DocumentException Reads a Document from the given URL or filename using SAX.
If the systemId contains a
| |
| read | back to summary |
|---|---|
| public Document read(InputStream in) throws DocumentException Reads a Document from the given stream using SAX
| |
| read | back to summary |
|---|---|
| public Document read(Reader reader) throws DocumentException Reads a Document from the given
| |
| read | back to summary |
|---|---|
| public Document read(InputStream in, String systemId) throws DocumentException Reads a Document from the given stream using SAX
| |
| read | back to summary |
|---|---|
| public Document read(Reader reader, String systemId) throws DocumentException
Reads a Document from the given
| |
| read | back to summary |
|---|---|
| public Document read(InputSource in) throws DocumentException
Reads a Document from the given
| |
| removeHandler | back to summary |
|---|---|
| public void removeHandler(String path) Removes the
| |
| resetHandlers | back to summary |
|---|---|
| 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. | |
| setDefaultHandler | back to summary |
|---|---|
| public void setDefaultHandler(ElementHandler handler) When multiple
| |
| setDispatchHandler | back to summary |
|---|---|
| protected void setDispatchHandler(DispatchHandler dispatchHandler) | |
| setDocumentFactory | back to summary |
|---|---|
| public void setDocumentFactory(DocumentFactory documentFactory)
This sets the
| |
| setEncoding | back to summary |
|---|---|
| public void setEncoding(String encoding) Sets encoding used for InputSource (null means system default encoding)
| |
| setEntityResolver | back to summary |
|---|---|
| public void setEntityResolver(EntityResolver entityResolver) Sets the entity resolver used to resolve entities.
| |
| setErrorHandler | back to summary |
|---|---|
| public void setErrorHandler(ErrorHandler errorHandler) Sets the
| |
| setFeature | back to summary |
|---|---|
| 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
| |
| setIgnoreComments | back to summary |
|---|---|
| public void setIgnoreComments(boolean ignoreComments) Sets whether we should ignore comments or not.
| |
| setIncludeExternalDTDDeclarations | back to summary |
|---|---|
| public void setIncludeExternalDTDDeclarations(boolean include) Sets whether DTD external declarations should be expanded into the DocumentType object or not.
| |
| setIncludeInternalDTDDeclarations | back to summary |
|---|---|
| public void setIncludeInternalDTDDeclarations(boolean include) Sets whether internal DTD declarations should be expanded into the DocumentType object or not.
| |
| setMergeAdjacentText | back to summary |
|---|---|
| public void setMergeAdjacentText(boolean mergeAdjacentText) Sets whether or not adjacent text nodes should be merged together when parsing.
| |
| setProperty | back to summary |
|---|---|
| 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
| |
| setStringInternEnabled | back to summary |
|---|---|
| public void setStringInternEnabled(boolean stringInternEnabled) Sets whether String interning is enabled or disabled for element & attribute names and namespace URIs
| |
| setStripWhitespaceText | back to summary |
|---|---|
| public void setStripWhitespaceText(boolean stripWhitespaceText) Sets whether whitespace between element start and end tags should be ignored.
| |
| setValidation | back to summary |
|---|---|
| public void setValidation(boolean validation) Sets the validation mode.
| |
| setXMLFilter | back to summary |
|---|---|
| public void setXMLFilter(XMLFilter filter) Sets the SAX filter to be used when filtering SAX events
| |
| setXMLReader | back to summary |
|---|---|
| public void setXMLReader(XMLReader reader) Sets the
| |
| setXMLReaderClassName | back to summary |
|---|---|
| public void setXMLReaderClassName(String xmlReaderClassName) throws SAXException Sets the class name of the
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public InputSource | resolveEntity(String
The public identifier of the external entity
being referenced, or null if none was supplied. publicId, String The system identifier of the external entity
being referenced. systemId)Implements org. |
| uriPrefix | back to summary |
|---|---|
| protected String uriPrefix | |
| SAXEntityResolver | back to summary |
|---|---|
| public SAXEntityResolver(String uriPrefix) | |
| resolveEntity | back to summary |
|---|---|
| public InputSource resolveEntity(String publicId, String systemId) Implements org. Doc from org. Allow the application to resolve external entities. The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream). Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL. If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.
| |