Package org.zkoss.idom.input
Class SAXBuilder
java.lang.Object
org.zkoss.idom.input.SAXBuilder
The builder based on SAX parsers.
A new instance of SAXHandler is created and configured
each time one of the build methods is called.
- Author:
- tomyeh
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSAXBuilder(boolean nsaware, boolean validate) Constructor that creates the parser on-the-fly.SAXBuilder(boolean nsaware, boolean validate, boolean smartIgnore) Constructor that creates the parser on-the-fly, that accepts an additional option, smartIgnore.SAXBuilder(SAXParser parser) Constructor which reuses a parser. -
Method Summary
Modifier and TypeMethodDescriptionfinal DocumentBuild an iDOM tree from a file.final Documentbuild(InputStream src) Build an iDOM tree from a input stream.final DocumentBuild an iDOM tree from a Reader.final DocumentBuild an iDOM tree from a URI string.final DocumentBuild an iDOM tree from a URL.final Documentbuild(InputSource src) Build an iDOM tree from a input source.final EntityResolverGets the org.xml.sax.EntityResolver.final ErrorHandlerGets the org.xml.sax.ErrorHandler.final IDOMFactoryGets the iDOM factory.final SAXParserGets the SAX parser.final booleanIndicates whether or not the factory is configured to produce parsers which converts CDATA to Text and appends it to the adjacent (if any) Text node.final booleanTests whether to expand entity reference nodes.final booleanIndicates whether or not the factory is configured to produce parsers which ignores comments.final booleanTests whether to ignore whitespaces in element content.final booleanTests whether or not this parser is configured to understand namespaces.final booleanTests whether or not this parser is configured to validate XML documents.protected SAXHandlerCreates a SAX Handler.final voidsetCoalescing(boolean coalescing) Specifies that the parser produced by this code will convert CDATA to Text and append it to the adjacent (if any) text.final voidSpecifies the org.xml.sax.EntityResolver to be used to resolve entities present in the XML document to be parsed.final voidSpecifies the org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.final voidsetExpandEntityReferences(boolean expand) Sets whether to expand entities during parsing.final voidsetIDOMFactory(IDOMFactory factory) Sets the iDOM factory.final voidsetIgnoringComments(boolean ignoreComments) Specifies that the parser produced by this code will ignore comments.final voidsetIgnoringElementContentWhitespace(boolean ignore) Sets whether the parser should eliminate whitespace in element content.
-
Constructor Details
-
SAXBuilder
Constructor which reuses a parser. -
SAXBuilder
public SAXBuilder(boolean nsaware, boolean validate) throws ParserConfigurationException, SAXException Constructor that creates the parser on-the-fly.- Parameters:
nsaware- whether the parser is namespace awarevalidate- whether the parser shall validate the document- Throws:
ParserConfigurationException- if a parser cannot be created which satisfies the requested configuration.SAXException- See Also:
-
SAXBuilder
public SAXBuilder(boolean nsaware, boolean validate, boolean smartIgnore) throws ParserConfigurationException, SAXException Constructor that creates the parser on-the-fly, that accepts an additional option, smartIgnore.When parsing XML for input purpose only, it is better to use this constructor with smartIgnore true, and then comments will be ignored CDATA will be coalesced with TEXT. A smaller DOM tree is formed.
- Parameters:
nsaware- whether the parser is namespace awarevalidate- whether the parser shall validate the documentsmartIgnore- whether to ignore comments and ignorable-whitespace (if validate is true), and to coalesce- Throws:
ParserConfigurationException- if a parser cannot be created which satisfies the requested configuration.SAXException
-
-
Method Details
-
isIgnoringElementContentWhitespace
public final boolean isIgnoringElementContentWhitespace()Tests whether to ignore whitespaces in element content. -
setIgnoringElementContentWhitespace
public final void setIgnoringElementContentWhitespace(boolean ignore) Sets whether the parser should eliminate whitespace in element content. They are known as "ignorable whitespace". Only whitespace which is contained within element content that has an element only content model will be eliminated (see XML Rec 2.10).For this setting to take effect requires that validation be turned on.
Default: false.
- Parameters:
ignore- Whether to ignore whitespaces in element content.
-
isExpandEntityReferences
public final boolean isExpandEntityReferences()Tests whether to expand entity reference nodes. -
setExpandEntityReferences
public final void setExpandEntityReferences(boolean expand) Sets whether to expand entities during parsing. A true means to expand entities as normal content. A false means to leave entities unexpanded asEntityReferenceobjects.Default: true.
- Parameters:
expand- whether entity expansion should occur.
-
isCoalescing
public final boolean isCoalescing()Indicates whether or not the factory is configured to produce parsers which converts CDATA to Text and appends it to the adjacent (if any) Text node.Default: false.
- Returns:
- true if the factory is configured to produce parsers which converts CDATA nodes to Text nodes and appends it to the adjacent (if any) Text node; false otherwise.
-
setCoalescing
public final void setCoalescing(boolean coalescing) Specifies that the parser produced by this code will convert CDATA to Text and append it to the adjacent (if any) text.Default: false.
-
isIgnoringComments
public final boolean isIgnoringComments()Indicates whether or not the factory is configured to produce parsers which ignores comments.Default: false.
- Returns:
- true if the factory is configured to produce parsers which ignores comments; false otherwise.
-
setIgnoringComments
public final void setIgnoringComments(boolean ignoreComments) Specifies that the parser produced by this code will ignore comments.Default: false.
-
setErrorHandler
Specifies the org.xml.sax.ErrorHandler to be used to report errors present in the XML document to be parsed.Default: null -- to use the default implementation and behavior.
-
getErrorHandler
Gets the org.xml.sax.ErrorHandler.- Returns:
- the error handler; null to use the default implementation
-
setEntityResolver
Specifies the org.xml.sax.EntityResolver to be used to resolve entities present in the XML document to be parsed.Default: null -- to use the default implementation and behavior.
-
getEntityResolver
Gets the org.xml.sax.EntityResolver.- Returns:
- the entity resolver; null to use the default implementation
-
isNamespaceAware
public final boolean isNamespaceAware()Tests whether or not this parser is configured to understand namespaces. -
isValidating
public final boolean isValidating()Tests whether or not this parser is configured to validate XML documents. -
getIDOMFactory
Gets the iDOM factory. Null for DefaultIDOMFactory.THE. -
setIDOMFactory
Sets the iDOM factory. Null for DefaultIDOMFactory.THE. -
getParser
Gets the SAX parser. -
build
Build an iDOM tree from a file.- Throws:
SAXExceptionIOException
-
build
Build an iDOM tree from a input stream.- Throws:
SAXExceptionIOException
-
build
Build an iDOM tree from a input source.- Throws:
SAXExceptionIOException
-
build
Build an iDOM tree from a URI string.- Throws:
SAXExceptionIOException
-
build
Build an iDOM tree from a URL.- Throws:
SAXExceptionIOException
-
build
Build an iDOM tree from a Reader.- Throws:
SAXExceptionIOException
-
newHandler
Creates a SAX Handler. Deriving class might override to provide a subclass of SAXHandler.- Throws:
SAXException
-