net.sf.saxon.dom

Class DocumentBuilderImpl


public class DocumentBuilderImpl
extends 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.

Method Summary

Configuration
getConfiguration()
Get the Saxon Configuration to be used by the document builder.
DOMImplementation
getDOMImplementation()
Obtain an instance of a DOMImplementation object.
int
getStripSpace()
Get the space-stripping action to be applied to the source document
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.
Document
newDocument()
Create a new Document Node.
Document
parse(File f)
Parse the content of the given file as an XML document and return a new DOM Document object.
Document
parse(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(EntityResolver er)
Specify the EntityResolver to be used to resolve entities present in the XML document to be parsed.
void
setErrorHandler(ErrorHandler eh)
Specify the ErrorHandler to be used by the parser.
void
setStripSpace(int stripAction)
Set the space-stripping action to be applied to the source document
void
setValidating(boolean state)
Determine whether the document builder should perform DTD validation
void
setXIncludeAware(boolean state)
Set state of XInclude processing.

Method Details

getConfiguration

public Configuration getConfiguration()
Get the Saxon Configuration to be used by the document builder. This is a non-JAXP method.
Returns:
the Configuration previously supplied to setConfiguration(Configuration), or the Configuration created automatically by Saxon on the first call to the parse method, or null if no Configuration has been supplied and the parse method has not been called.
Since:
Saxon 8.8

getDOMImplementation

public DOMImplementation getDOMImplementation()
Obtain an instance of a DOMImplementation object.
Returns:
A new instance of a DOMImplementation.

getStripSpace

public int getStripSpace()
Get the space-stripping action to be applied to the source document
Since:
8.9

isNamespaceAware

public boolean isNamespaceAware()
Indicates whether or not this document builder is configured to understand namespaces.
Returns:
true if this document builder is configured to understand namespaces. This implementation always returns true.

isValidating

public boolean isValidating()
Indicates whether or not this document builder is configured to validate XML documents against a DTD.
Returns:
true if this parser is configured to validate XML documents against a DTD; false otherwise.

isXIncludeAware

public boolean isXIncludeAware()
Get the XInclude processing mode for this parser.
Returns:
the return value of the javax.xml.parsers.DocumentBuilderFactory.isXIncludeAware() when this parser was created from factory.
Since:
JAXP 1.5, Saxon 8.9
See Also:
javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(boolean)

newDocument

public Document newDocument()
Create a new Document Node.
Returns:
a new Document Node. The returned document will be of little use, because it is immutable. But it can be used in a DOMResult as the result of a transformation

parse

public Document parse(File f)
            throws SAXException,
                   IOException
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.

Parameters:
f - The file containing the XML to parse.
Returns:
A new DOM Document object.

parse

public Document parse(InputSource in)
            throws SAXException
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.

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 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.

Since:
Saxon 8.8

setEntityResolver

public void setEntityResolver(EntityResolver er)
Specify the EntityResolver to be used to resolve entities present in the XML document to be parsed. Setting this to null will result in the underlying implementation using the EntityResolver registered with the XMLReader contained in the InputSource.
Parameters:
er - The EntityResolver to be used to resolve entities present in the XML document to be parsed.

setErrorHandler

public void setErrorHandler(ErrorHandler eh)
Specify the ErrorHandler to be used by the parser. Setting this to null will result in the underlying implementation using using the ErrorHandler registered with the XMLReader contained in the InputSource.
Parameters:
eh - The ErrorHandler to be used by the parser.

setStripSpace

public void setStripSpace(int stripAction)
Set the space-stripping action to be applied to the source document
Since:
8.9

setValidating

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

setXIncludeAware

public void setXIncludeAware(boolean state)
Parameters:
state - Set XInclude processing to true or false