Class DocumentBuilderImpl


  • public class DocumentBuilderImpl
    extends javax.xml.parsers.DocumentBuilder
    This class implements the JAXP DocumentBuilder interface, allowing a Saxon TinyTree to be constructed using standard JAXP parsing interfaces. The returned DOM document node is a wrapper over the Saxon TinyTree structure. Note that although this wrapper implements the DOM interfaces, it is read-only, and all attempts to update it will throw an exception. No schema or DTD validation is carried out on the document. The DocumentBuilder is always namespace-aware.

    A DocumentBuilderImpl object contains an instance of ParseOptions; many of the properties of the DocumentBuilderImpl map directly to the properties of the underlying ParseOptions, and changes can be made at either level.

    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Configuration getConfiguration()
      Get the Saxon Configuration to be used by the document builder.
      org.w3c.dom.DOMImplementation getDOMImplementation()
      Obtain an instance of a DOMImplementation object.
      ParseOptions getParseOptions()
      Get the XML parsing options that have been set using setParseOptions and other setter methods
      int getStripSpace()
      Deprecated.
      boolean isNamespaceAware()
      Indicates whether or not this document builder is configured to understand namespaces.
      boolean isValidating()
      Indicates whether or not this document builder is configured to validate XML documents against a DTD.
      boolean isXIncludeAware()
      Get the XInclude processing mode for this parser.
      org.w3c.dom.Document newDocument()
      Create a new Document Node.
      org.w3c.dom.Document parse​(java.io.File f)
      Parse the content of the given file as an XML document and return a new DOM Document object.
      org.w3c.dom.Document parse​(org.xml.sax.InputSource in)
      Parse the content of the given input source as an XML document and return a new DOM Document object.
      void setConfiguration​(Configuration config)
      Set the Saxon Configuration to be used by the document builder.
      void setEntityResolver​(org.xml.sax.EntityResolver er)
      Specify the EntityResolver to be used to resolve entities present in the XML document to be parsed.
      void setErrorHandler​(org.xml.sax.ErrorHandler eh)
      Specify the ErrorHandler to be used by the parser.
      void setParseOptions​(ParseOptions options)
      Set the XML parsing options to be used
      void setStripSpace​(int stripAction)
      void setValidating​(boolean state)
      Determine whether the document builder should perform DTD validation
      void setXIncludeAware​(boolean state)
      Set state of XInclude processing.
      • Methods inherited from class javax.xml.parsers.DocumentBuilder

        getSchema, parse, parse, parse, reset
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DocumentBuilderImpl

        public DocumentBuilderImpl()
    • Method Detail

      • setConfiguration

        public void setConfiguration​(Configuration config)
        Set the Saxon Configuration to be used by the document builder. This non-JAXP method must be called if the resulting document is to be used within a Saxon query or transformation. If no Configuration is supplied, Saxon creates a Configuration on the first call to the parse(org.xml.sax.InputSource) method, and subsequent calls reuse the same Configuration.

        As an alternative to calling this method, a Configuration can be supplied by calling setAttribute(FeatureKeys.CONFIGURATION, config) on the DocumentBuilderFactory object, where config can be obtained by calling getAttribute(FeatureKeys.CONFIGURATION) on the TransformerFactory.

        Parameters:
        config - the Saxon configuration
        Since:
        Saxon 8.8
      • isNamespaceAware

        public boolean isNamespaceAware()
        Indicates whether or not this document builder is configured to understand namespaces.
        Specified by:
        isNamespaceAware in class javax.xml.parsers.DocumentBuilder
        Returns:
        true if this document builder is configured to understand namespaces. This implementation always returns true.
      • setValidating

        public void setValidating​(boolean state)
        Determine whether the document builder should perform DTD validation
        Parameters:
        state - set to true to request DTD validation
      • isValidating

        public boolean isValidating()
        Indicates whether or not this document builder is configured to validate XML documents against a DTD.
        Specified by:
        isValidating in class javax.xml.parsers.DocumentBuilder
        Returns:
        true if this parser is configured to validate XML documents against a DTD; false otherwise.
      • newDocument

        public org.w3c.dom.Document newDocument()
        Create a new Document Node.
        Specified by:
        newDocument in class javax.xml.parsers.DocumentBuilder
        Throws:
        java.lang.UnsupportedOperationException - (always). The only way to build a document using this DocumentBuilder implementation is by using the parse() method.
      • parse

        public org.w3c.dom.Document parse​(org.xml.sax.InputSource in)
                                   throws org.xml.sax.SAXException
        Parse the content of the given input source as an XML document and return a new DOM Document object.

        Note: for this document to be usable as part of a Saxon query or transformation, the document should be built within the Configuration in which that query or transformation is running. This can be achieved using the non-JAXP setConfiguration(net.sf.saxon.Configuration) method.

        Specified by:
        parse in class javax.xml.parsers.DocumentBuilder
        Parameters:
        in - InputSource containing the content to be parsed. Note that if an EntityResolver or ErrorHandler has been supplied, then the XMLReader contained in this InputSource will be modified to register this EntityResolver or ErrorHandler, replacing any that was previously registered.
        Returns:
        A new DOM Document object.
        Throws:
        org.xml.sax.SAXException - If any parse errors occur.
      • parse

        public org.w3c.dom.Document parse​(java.io.File f)
                                   throws org.xml.sax.SAXException
        Parse the content of the given file as an XML document and return a new DOM Document object. An IllegalArgumentException is thrown if the File is null null.

        This implementation differs from the parent implementation by using a correct algorithm for filename-to-uri conversion.

        Overrides:
        parse in class javax.xml.parsers.DocumentBuilder
        Parameters:
        f - The file containing the XML to parse.
        Returns:
        A new DOM Document object.
        Throws:
        org.xml.sax.SAXException - If any parse errors occur.
      • setEntityResolver

        public void setEntityResolver​(org.xml.sax.EntityResolver er)
        Specify the EntityResolver to be used to resolve entities present in the XML document to be parsed.
        Specified by:
        setEntityResolver in class javax.xml.parsers.DocumentBuilder
        Parameters:
        er - The EntityResolver to be used to resolve entities present in the XML document to be parsed.
      • setErrorHandler

        public void setErrorHandler​(org.xml.sax.ErrorHandler eh)
        Specify the ErrorHandler to be used by the parser.
        Specified by:
        setErrorHandler in class javax.xml.parsers.DocumentBuilder
        Parameters:
        eh - The ErrorHandler to be used by the parser.
      • getDOMImplementation

        public org.w3c.dom.DOMImplementation getDOMImplementation()
        Obtain an instance of a DOMImplementation object.
        Specified by:
        getDOMImplementation in class javax.xml.parsers.DocumentBuilder
        Returns:
        A new instance of a DOMImplementation.
      • setXIncludeAware

        public void setXIncludeAware​(boolean state)

        Set state of XInclude processing.

        If XInclude markup is found in the document instance, should it be processed as specified in XML Inclusions (XInclude) Version 1.0.

        XInclude processing defaults to false.

        Parameters:
        state - Set XInclude processing to true or false
      • isXIncludeAware

        public boolean isXIncludeAware()

        Get the XInclude processing mode for this parser.

        Overrides:
        isXIncludeAware in class javax.xml.parsers.DocumentBuilder
        Returns:
        the return value of the DocumentBuilderFactory.isXIncludeAware() when this parser was created from factory.
        Throws:
        java.lang.UnsupportedOperationException - For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.
        Since:
        JAXP 1.5, Saxon 8.9
        See Also:
        DocumentBuilderFactory.setXIncludeAware(boolean)
      • setParseOptions

        public void setParseOptions​(ParseOptions options)
        Set the XML parsing options to be used
        Parameters:
        options - the XML parsing options. Options set using this method will override any options previously set using other methods; options subsequently set using other methods will modify the parseOptions object supplied using this method
        Since:
        9.3
      • getParseOptions

        public ParseOptions getParseOptions()
        Get the XML parsing options that have been set using setParseOptions and other setter methods
        Returns:
        the XML parsing options to be used
        Since:
        9.3