Class SAXBuilder

java.lang.Object
org.zkoss.idom.input.SAXBuilder

public class SAXBuilder extends Object
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 Details

    • SAXBuilder

      public SAXBuilder(SAXParser parser)
      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 aware
      validate - 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 aware
      validate - whether the parser shall validate the document
      smartIgnore - 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 as EntityReference objects.

      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

      public final void setErrorHandler(ErrorHandler eh)
      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

      public final ErrorHandler getErrorHandler()
      Gets the org.xml.sax.ErrorHandler.
      Returns:
      the error handler; null to use the default implementation
    • setEntityResolver

      public final void setEntityResolver(EntityResolver er)
      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

      public final EntityResolver 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

      public final IDOMFactory getIDOMFactory()
      Gets the iDOM factory. Null for DefaultIDOMFactory.THE.
    • setIDOMFactory

      public final void setIDOMFactory(IDOMFactory factory)
      Sets the iDOM factory. Null for DefaultIDOMFactory.THE.
    • getParser

      public final SAXParser getParser()
      Gets the SAX parser.
    • build

      public final Document build(File src) throws SAXException, IOException
      Build an iDOM tree from a file.
      Throws:
      SAXException
      IOException
    • build

      public final Document build(InputStream src) throws SAXException, IOException
      Build an iDOM tree from a input stream.
      Throws:
      SAXException
      IOException
    • build

      public final Document build(InputSource src) throws SAXException, IOException
      Build an iDOM tree from a input source.
      Throws:
      SAXException
      IOException
    • build

      public final Document build(String uri) throws SAXException, IOException
      Build an iDOM tree from a URI string.
      Throws:
      SAXException
      IOException
    • build

      public final Document build(URL url) throws SAXException, IOException
      Build an iDOM tree from a URL.
      Throws:
      SAXException
      IOException
    • build

      public final Document build(Reader src) throws SAXException, IOException
      Build an iDOM tree from a Reader.
      Throws:
      SAXException
      IOException
    • newHandler

      protected SAXHandler newHandler() throws SAXException
      Creates a SAX Handler. Deriving class might override to provide a subclass of SAXHandler.
      Throws:
      SAXException