Class DocumentBuilderImpl
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the Saxon Configuration to be used by the document builder.Obtain an instance of aDOMImplementationobject.Get the XML parsing options that have been set using setParseOptions and other setter methodsintDeprecated.booleanIndicates whether or not this document builder is configured to understand namespaces.booleanIndicates whether or not this document builder is configured to validate XML documents against a DTD.booleanGet the XInclude processing mode for this parser.Create a new Document Node.Parse the content of the given file as an XML document and return a new DOMDocumentobject.parse(InputSource in) Parse the content of the given input source as an XML document and return a new DOMDocumentobject.voidsetConfiguration(Configuration config) Set the Saxon Configuration to be used by the document builder.voidSpecify theEntityResolverto be used to resolve entities present in the XML document to be parsed.voidSpecify theErrorHandlerto be used by the parser.voidsetParseOptions(ParseOptions options) Set the XML parsing options to be usedvoidsetStripSpace(int stripAction) Deprecated.since 10.0: useParseOptions.withSpaceStrippingRule(SpaceStrippingRule)voidsetValidating(boolean state) Determine whether the document builder should perform DTD validationvoidsetXIncludeAware(boolean state) Set state of XInclude processing.
-
Constructor Details
-
DocumentBuilderImpl
public DocumentBuilderImpl()
-
-
Method Details
-
setConfiguration
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 theparse(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 theDocumentBuilderFactoryobject, whereconfigcan be obtained by callinggetAttribute(FeatureKeys.CONFIGURATION)on theTransformerFactory.- Parameters:
config- the Saxon configuration- Since:
- Saxon 8.8
-
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(net.sf.saxon.Configuration), or the Configuration created automatically by Saxon on the first call to theparse(org.xml.sax.InputSource)method, or a newly constructed Configuration if no Configuration has been supplied and theparse(org.xml.sax.InputSource)method has not been called. - Since:
- Saxon 8.8
-
isNamespaceAware
public boolean isNamespaceAware()Indicates whether or not this document builder is configured to understand namespaces.- Specified by:
isNamespaceAwarein classDocumentBuilder- 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:
isValidatingin classDocumentBuilder- Returns:
- true if this parser is configured to validate XML documents against a DTD; false otherwise.
-
newDocument
Create a new Document Node.- Specified by:
newDocumentin classDocumentBuilder- Throws:
UnsupportedOperationException- (always). The only way to build a document using this DocumentBuilder implementation is by using the parse() method.
-
parse
Parse the content of the given input source as an XML document and return a new DOMDocumentobject.Note: for this document to be usable as part of a Saxon query or transformation, the document should be built within the
Configurationin which that query or transformation is running. This can be achieved using the non-JAXPsetConfiguration(net.sf.saxon.Configuration)method.- Specified by:
parsein classDocumentBuilder- 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:
SAXException- If any parse errors occur.
-
parse
Parse the content of the given file as an XML document and return a new DOMDocumentobject. AnIllegalArgumentExceptionis thrown if theFileisnullnull.This implementation differs from the parent implementation by using a correct algorithm for filename-to-uri conversion.
- Overrides:
parsein classDocumentBuilder- Parameters:
f- The file containing the XML to parse.- Returns:
- A new DOM Document object.
- Throws:
SAXException- If any parse errors occur.
-
setEntityResolver
Specify theEntityResolverto be used to resolve entities present in the XML document to be parsed.- Specified by:
setEntityResolverin classDocumentBuilder- Parameters:
er- TheEntityResolverto be used to resolve entities present in the XML document to be parsed.
-
setErrorHandler
Specify theErrorHandlerto be used by the parser.- Specified by:
setErrorHandlerin classDocumentBuilder- Parameters:
eh- TheErrorHandlerto be used by the parser.
-
getDOMImplementation
Obtain an instance of aDOMImplementationobject.- Specified by:
getDOMImplementationin classDocumentBuilder- 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 totrueorfalse
-
isXIncludeAware
public boolean isXIncludeAware()Get the XInclude processing mode for this parser.
- Overrides:
isXIncludeAwarein classDocumentBuilder- Returns:
- the return value of
the
DocumentBuilderFactory.isXIncludeAware()when this parser was created from factory. - Throws:
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:
-
setStripSpace
Deprecated.since 10.0: useParseOptions.withSpaceStrippingRule(SpaceStrippingRule)Set the space-stripping action to be applied to the source document- Parameters:
stripAction- one ofWhitespace.IGNORABLE,Whitespace.ALL, orWhitespace.NONE- Since:
- 8.9
-
getStripSpace
Deprecated.since 10.0: useParseOptions.getSpaceStrippingRule()Get the space-stripping action to be applied to the source document- Returns:
- one of
Whitespace.IGNORABLE,Whitespace.ALL, orWhitespace.NONE - Since:
- 8.9
-
setParseOptions
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
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
-
ParseOptions.getSpaceStrippingRule()