org.xml.sax.InputSource instance using a SAX parser. The builder uses a
third-party SAX parser (chosen by JAXP by default, or you can choose
manually) to handle the parsing duties and simply listens to the SAX events
to construct a document. Details which SAX does not provide, such as
whitespace outside the root element, are not represented in the JDOM
document. Information about SAX can be found at http://www.saxproject.org.
Known issues: Relative paths for a DocType or EntityRef may
be converted by the SAX parser into absolute paths.
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String | DEFAULT_SAX_DRIVER
Default parser class to use. |
| private boolean | expand
Whether expansion of entities should occur |
| private JDOMFactory | factory
The factory for creating new JDOM objects |
| private boolean | fastReconfigure
Whether to use fast parser reconfiguration |
| private HashMap | features
User-specified features to be set on the SAX parser |
| private boolean | ignoringBoundaryWhite
Whether to ignore all whitespace content |
| private boolean | ignoringWhite
Whether to ignore ignorable whitespace |
| private HashMap | properties
User-specified properties to be set on the SAX parser |
| private boolean | reuseParser
Whether parser reuse is allowed. |
| private String | saxDriverClass
Adapter class to use |
| private DTDHandler | saxDTDHandler
DTDHandler class to use |
| private EntityResolver | saxEntityResolver
EntityResolver class to use |
| private ErrorHandler | saxErrorHandler
ErrorHandler class to use |
| private XMLReader | saxParser
The current SAX parser, if parser reuse has been activated. |
| private XMLFilter | saxXMLFilter
XMLFilter instance to use |
| private boolean | skipNextEntityExpandConfig
Whether to to try entity expansion in fast parser reconfiguration |
| private boolean | skipNextLexicalReportingConfig
Whether to try lexical reporting in fast parser reconfiguration |
| private boolean | validate
Whether validation should occur |
| Access | Constructor and Description |
|---|---|
| public | SAXBuilder()
Creates a new SAXBuilder which will attempt to first locate a parser via JAXP, then will try to use a set of default SAX Drivers. |
| public | SAXBuilder(boolean
boolean indicating if
validation should occur.Creates a new SAXBuilder which will attempt to first locate a parser via JAXP, then will try to use a set of default SAX Drivers. |
| public | SAXBuilder(String
String name of SAX Driver
to use for parsing.Creates a new SAXBuilder using the specified SAX parser. |
| public | SAXBuilder(String
String name of SAX Driver
to use for parsing.boolean indicating if
validation should occur.Creates a new SAXBuilder using the specified SAX parser. |
| Modifier and Type | Method and Description |
|---|---|
| public Document | Returns: Document resultant Document objectInputSource to read fromThis builds a document from the supplied input source. |
| public Document | Returns: Document resultant Document objectInputStream to read fromThis builds a document from the supplied input stream. |
| public Document | |
| public Document | |
| public Document | Returns: Document resultant Document objectInputStream to read from.base for resolving relative URIs systemId)This builds a document from the supplied input stream. |
| public Document | |
| public Document | |
| public Document | |
| protected void | configureContentHandler(SAXHandler
The SAXHandler to configure contentHandler)This configures the SAXHandler that will be used to build the Document. |
| protected void | configureParser(XMLReader parser, SAXHandler contentHandler)
This configures the XMLReader to be used for reading the XML document. |
| protected SAXHandler | Returns: SAXHandler - resultant SAXHandler object.This creates the SAXHandler that will be used to build the Document. |
| protected XMLReader | Returns: XMLReader - resultant XMLReader object.This creates the XMLReader to be used for reading the XML document. |
| private static URL | |
| public String | Returns: the driver class assigned in the constructorReturns the driver class assigned in the constructor, or null if none. |
| public DTDHandler | |
| public EntityResolver | Returns: the EntityResolver assignedReturns the |
| public ErrorHandler | Returns: the ErrorHandler assigned, or null if noneReturns the |
| public boolean | Returns: whether entities are being expandedReturns whether or not entities are being expanded into normal text content. |
| public JDOMFactory | |
| public boolean | Returns: boolean - whether only whitespace content will
be ignored during build.Returns whether or not the parser will elminate element content containing only whitespace. |
| public boolean | Returns: whether element content whitespace is to be ignored during the buildReturns whether element content whitespace is to be ignored during the build. |
| public boolean | Returns: whether the contained SAX parser instance is reused across multiple parsesReturns whether the contained SAX parser instance is reused across multiple parses. |
| public boolean | Returns: whether validation is to be performed during the buildReturns whether validation is to be performed during the build. |
| public XMLFilter | Returns: the XMLFilter used during parsingReturns the |
| private void | internalSetFeature(XMLReader parser, String feature, boolean value, String displayName)
Tries to set a feature on the parser. |
| private void | internalSetProperty(XMLReader parser, String property, Object value, String displayName)
Tries to set a property on the parser. |
| public void | |
| public void | setEntityResolver(EntityResolver
EntityResolverThis sets custom EntityResolver for the |
| public void | setErrorHandler(ErrorHandler
ErrorHandlerThis sets custom ErrorHandler for the |
| public void | setExpandEntities(boolean
boolean indicating whether entity expansion
should occur.This sets whether or not to expand entities for the builder. |
| public void | |
| public void | setFastReconfigure(boolean
Whether to do a fast reconfiguration of the parser fastReconfigure)Specifies whether this builder will do fast reconfiguration of the underlying SAX parser when reuseParser is true. |
| public void | setFeature(String
The feature name, which is a fully-qualified URI. name, boolean The requested state of the feature (true or false). value)This sets a feature on the SAX parser. |
| private void | |
| public void | setIgnoringBoundaryWhitespace(boolean
Whether to ignore whitespace-only text
noes ignoringBoundaryWhite)Specifies whether or not the parser should elminate boundary whitespace, a term that indicates whitespace-only text between element tags. |
| public void | setIgnoringElementContentWhitespace(boolean
Whether to ignore ignorable whitespace ignoringWhite)Specifies whether or not the parser should elminate whitespace in element content (sometimes known as "ignorable whitespace") when building the document. |
| public void | setProperty(String
The property name, which is a fully-qualified URI. name, Object The requested value for the property. value)This sets a property on the SAX parser. |
| public void | setReuseParser(boolean
Whether to reuse the SAX parser. reuseParser)Specifies whether this builder shall reuse the same SAX parser when performing subsequent parses or allocate a new parser for each parse. |
| public void | setValidation(boolean
boolean indicating whether validation
should occur.This sets validation for the builder. |
| public void | setXMLFilter(XMLFilter
the filter to use xmlFilter)This sets a custom |
| CVS_ID | back to summary |
|---|---|
| private static final String CVS_ID | |
| DEFAULT_SAX_DRIVER | back to summary |
|---|---|
| private static final String DEFAULT_SAX_DRIVER Default parser class to use. This is used when no other parser is given and JAXP isn't available. | |
| expand | back to summary |
|---|---|
| private boolean expand Whether expansion of entities should occur | |
| factory | back to summary |
|---|---|
| private JDOMFactory factory The factory for creating new JDOM objects | |
| fastReconfigure | back to summary |
|---|---|
| private boolean fastReconfigure Whether to use fast parser reconfiguration | |
| features | back to summary |
|---|---|
| private HashMap<K, V> features User-specified features to be set on the SAX parser | |
| ignoringBoundaryWhite | back to summary |
|---|---|
| private boolean ignoringBoundaryWhite Whether to ignore all whitespace content | |
| ignoringWhite | back to summary |
|---|---|
| private boolean ignoringWhite Whether to ignore ignorable whitespace | |
| properties | back to summary |
|---|---|
| private HashMap<K, V> properties User-specified properties to be set on the SAX parser | |
| reuseParser | back to summary |
|---|---|
| private boolean reuseParser Whether parser reuse is allowed. Default: | |
| saxDriverClass | back to summary |
|---|---|
| private String saxDriverClass Adapter class to use | |
| saxDTDHandler | back to summary |
|---|---|
| private DTDHandler saxDTDHandler DTDHandler class to use | |
| saxEntityResolver | back to summary |
|---|---|
| private EntityResolver saxEntityResolver EntityResolver class to use | |
| saxErrorHandler | back to summary |
|---|---|
| private ErrorHandler saxErrorHandler ErrorHandler class to use | |
| saxParser | back to summary |
|---|---|
| private XMLReader saxParser The current SAX parser, if parser reuse has been activated. | |
| saxXMLFilter | back to summary |
|---|---|
| private XMLFilter saxXMLFilter XMLFilter instance to use | |
| skipNextEntityExpandConfig | back to summary |
|---|---|
| private boolean skipNextEntityExpandConfig Whether to to try entity expansion in fast parser reconfiguration | |
| skipNextLexicalReportingConfig | back to summary |
|---|---|
| private boolean skipNextLexicalReportingConfig Whether to try lexical reporting in fast parser reconfiguration | |
| validate | back to summary |
|---|---|
| private boolean validate Whether validation should occur | |
| SAXBuilder | back to summary |
|---|---|
| public SAXBuilder() Creates a new SAXBuilder which will attempt to first locate a parser via JAXP, then will try to use a set of default SAX Drivers. The underlying parser will not validate. | |
| SAXBuilder | back to summary |
|---|---|
| public SAXBuilder(boolean validate) Creates a new SAXBuilder which will attempt to first locate a parser via JAXP, then will try to use a set of default SAX Drivers. The underlying parser will validate or not according to the given parameter.
| |
| SAXBuilder | back to summary |
|---|---|
| public SAXBuilder(String saxDriverClass) Creates a new SAXBuilder using the specified SAX parser. The underlying parser will not validate.
| |
| SAXBuilder | back to summary |
|---|---|
| public SAXBuilder(String saxDriverClass, boolean validate) Creates a new SAXBuilder using the specified SAX parser. The underlying parser will validate or not according to the given parameter.
| |
| build | back to summary |
|---|---|
| public Document build(InputSource in) throws JDOMException, IOException This builds a document from the supplied input source.
| |
| build | back to summary |
|---|---|
| public Document build(InputStream in) throws JDOMException, IOException This builds a document from the supplied input stream.
| |
| build | back to summary |
|---|---|
| public Document build(File file) throws JDOMException, IOException This builds a document from the supplied filename.
| |
| build | back to summary |
|---|---|
| public Document build(URL url) throws JDOMException, IOException This builds a document from the supplied URL.
| |
| build | back to summary |
|---|---|
| public Document build(InputStream in, String systemId) throws JDOMException, IOException This builds a document from the supplied input stream.
| |
| build | back to summary |
|---|---|
| public Document build(Reader characterStream) throws JDOMException, IOException This builds a document from the supplied Reader. It's the programmer's responsibility to make sure the reader matches the encoding of the file. It's often easier and safer to use an InputStream rather than a Reader, and to let the parser auto-detect the encoding from the XML declaration.
| |
| build | back to summary |
|---|---|
| public Document build(Reader characterStream, String systemId) throws JDOMException, IOException This builds a document from the supplied Reader. It's the programmer's responsibility to make sure the reader matches the encoding of the file. It's often easier and safer to use an InputStream rather than a Reader, and to let the parser auto-detect the encoding from the XML declaration.
| |
| build | back to summary |
|---|---|
| public Document build(String systemId) throws JDOMException, IOException This builds a document from the supplied URI.
| |
| configureContentHandler | back to summary |
|---|---|
| protected void configureContentHandler(SAXHandler contentHandler) This configures the SAXHandler that will be used to build the Document. The default implementation simply passes through some configuration settings that were set on the SAXBuilder: setExpandEntities() and setIgnoringElementContentWhitespace().
| |
| configureParser | back to summary |
|---|---|
| protected void configureParser(XMLReader parser, SAXHandler contentHandler) throws JDOMException This configures the XMLReader to be used for reading the XML document.
The default implementation sets various options on the given XMLReader,
such as validation, DTD resolution, entity handlers, etc., according
to the options that were set (e.g. via | |
| createContentHandler | back to summary |
|---|---|
| protected SAXHandler createContentHandler() This creates the SAXHandler that will be used to build the Document.
| |
| createParser | back to summary |
|---|---|
| protected XMLReader createParser() throws JDOMException This creates the XMLReader to be used for reading the XML document. The default behavior is to (1) use the saxDriverClass, if it has been set, (2) try to obtain a parser from JAXP, if it is available, and (3) if all else fails, use a hard-coded default parser (currently the Xerces parser). Subclasses may override this method to determine the parser to use in a different way.
| |
| fileToURL | back to summary |
|---|---|
| private static URL fileToURL(File file) throws MalformedURLException Custom File.toUrl() implementation to handle special chars in file names
| |
| getDriverClass | back to summary |
|---|---|
| public String getDriverClass() Returns the driver class assigned in the constructor, or null if none.
| |
| getDTDHandler | back to summary |
|---|---|
| public DTDHandler getDTDHandler() Returns the
| |
| getEntityResolver | back to summary |
|---|---|
| public EntityResolver getEntityResolver() Returns the
| |
| getErrorHandler | back to summary |
|---|---|
| public ErrorHandler getErrorHandler() Returns the
| |
| getExpandEntities | back to summary |
|---|---|
| public boolean getExpandEntities() Returns whether or not entities are being expanded into normal text content.
| |
| getFactory | back to summary |
|---|---|
| public JDOMFactory getFactory() Returns the current
| |
| getIgnoringBoundaryWhitespace | back to summary |
|---|---|
| public boolean getIgnoringBoundaryWhitespace() Returns whether or not the parser will elminate element content containing only whitespace.
| |
| getIgnoringElementContentWhitespace | back to summary |
|---|---|
| public boolean getIgnoringElementContentWhitespace() Returns whether element content whitespace is to be ignored during the build.
| |
| getReuseParser | back to summary |
|---|---|
| public boolean getReuseParser() Returns whether the contained SAX parser instance is reused across multiple parses. The default is true.
| |
| getValidation | back to summary |
|---|---|
| public boolean getValidation() Returns whether validation is to be performed during the build.
| |
| getXMLFilter | back to summary |
|---|---|
| public XMLFilter getXMLFilter() Returns the
| |
| internalSetFeature | back to summary |
|---|---|
| private void internalSetFeature(XMLReader parser, String feature, boolean value, String displayName) throws JDOMException Tries to set a feature on the parser. If the feature cannot be set, throws a JDOMException describing the problem. | |
| internalSetProperty | back to summary |
|---|---|
| private void internalSetProperty(XMLReader parser, String property, Object value, String displayName) throws JDOMException Tries to set a property on the parser. If the property cannot be set, throws a JDOMException describing the problem. | |
| setDTDHandler | back to summary |
|---|---|
| public void setDTDHandler(DTDHandler dtdHandler) This sets custom DTDHandler for the
| |
| setEntityResolver | back to summary |
|---|---|
| public void setEntityResolver(EntityResolver entityResolver) This sets custom EntityResolver for the
| |
| setErrorHandler | back to summary |
|---|---|
| public void setErrorHandler(ErrorHandler errorHandler) This sets custom ErrorHandler for the
| |
| setExpandEntities | back to summary |
|---|---|
| public void setExpandEntities(boolean expand)
This sets whether or not to expand entities for the builder.
A true means to expand entities as normal content. A false means to
leave entities unexpanded as When this setting is false, the internal DTD subset is retained; when this setting is true, the internal DTD subset is not retained. Note that Xerces (at least up to 1.4.4) has a bug where entities in attribute values will be misreported if this flag is turned off, resulting in entities to appear within element content. When turning entity expansion off either avoid entities in attribute values, or use another parser like Crimson. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6111
| |
| setFactory | back to summary |
|---|---|
| public void setFactory(JDOMFactory factory) This sets a custom JDOMFactory for the builder. Use this to build the tree with your own subclasses of the JDOM classes.
| |
| setFastReconfigure | back to summary |
|---|---|
| public void setFastReconfigure(boolean fastReconfigure) Specifies whether this builder will do fast reconfiguration of the
underlying SAX parser when reuseParser is true. This improves
performance in cases where SAXBuilders are reused and lots of small
documents are frequently parsed. This avoids attempting to set features
on the SAX parser each time build() is called which result in
SaxNotRecognizedExceptions. This should ONLY be set for builders where
this specific case is an issue. The default value of this setting is
| |
| setFeature | back to summary |
|---|---|
| public void setFeature(String name, boolean value) This sets a feature on the SAX parser. See the SAX documentation for . more information. Note SAXBuilder requires that some particular features of the SAX parser be set up in certain ways for it to work properly. The list of such features may change in the future. Therefore, the use of this method may cause parsing to break, and even if it doesn't break anything today it might break parsing in a future JDOM version, because what JDOM parsers require may change over time. Use with caution.
| |
| setFeaturesAndProperties | back to summary |
|---|---|
| private void setFeaturesAndProperties(XMLReader parser, boolean coreFeatures) throws JDOMException | |
| setIgnoringBoundaryWhitespace | back to summary |
|---|---|
| public void setIgnoringBoundaryWhitespace(boolean ignoringBoundaryWhite) Specifies whether or not the parser should elminate boundary whitespace,
a term that indicates whitespace-only text between element tags. This
feature is a lot like
| |
| setIgnoringElementContentWhitespace | back to summary |
|---|---|
| public void setIgnoringElementContentWhitespace(boolean ignoringWhite) Specifies whether or not the parser should elminate whitespace in
element content (sometimes known as "ignorable whitespace") when
building the document. Only whitespace which is contained within
element content that has an element only content model will be
eliminated (see XML Rec 3.2.1). For this setting to take effect
requires that validation be turned on. The default value of this
setting is
| |
| setProperty | back to summary |
|---|---|
| public void setProperty(String name, Object value) This sets a property on the SAX parser. See the SAX documentation for more information. Note SAXBuilder requires that some particular properties of the SAX parser be set up in certain ways for it to work properly. The list of such properties may change in the future. Therefore, the use of this method may cause parsing to break, and even if it doesn't break anything today it might break parsing in a future JDOM version, because what JDOM parsers require may change over time. Use with caution. | |
| setReuseParser | back to summary |
|---|---|
| public void setReuseParser(boolean reuseParser) Specifies whether this builder shall reuse the same SAX parser
when performing subsequent parses or allocate a new parser for
each parse. The default value of this setting is
Note As SAX parser instances are not thread safe, the parser reuse feature should not be used with SAXBuilder instances shared among threads.
| |
| setValidation | back to summary |
|---|---|
| public void setValidation(boolean validate) This sets validation for the builder.
| |
| setXMLFilter | back to summary |
|---|---|
| public void setXMLFilter(XMLFilter xmlFilter) This sets a custom
| |