javax.xml.parsers
Class DocumentBuilderFactory
java.lang.Object
javax.xml.parsers.DocumentBuilderFactory
public abstract class DocumentBuilderFactory
extends java.lang.Object
Defines a factory API that enables applications to obtain a
parser that produces DOM object trees from XML documents.
An implementation of the DocumentBuilderFactory
class is
NOT guaranteed to be thread safe. It is up to the user application
to make sure about the use of the DocumentBuilderFactory
from
more than one thread. Alternatively the application can have one instance
of the DocumentBuilderFactory
per thread.
An application can use the same instance of the factory to obtain one or
more instances of the DocumentBuilder
provided the instance
of the factory isn't being used in more than one thread at a time.
Version:
- JAXP 1.0
Object | getAttribute(String name) - Allows the user to retrieve specific attributes on the underlying
implementation.
|
boolean | isCoalescing() - Indicates whether or not the factory is configured to produce
parsers which converts CDATA nodes to Text nodes and appends it to
the adjacent (if any) Text node.
|
boolean | isExpandEntityReferences() - Indicates whether or not the factory is configured to produce
parsers which expand entity reference nodes.
|
boolean | isIgnoringComments() - Indicates whether or not the factory is configured to produce
parsers which ignores comments.
|
boolean | isIgnoringElementContentWhitespace() - Indicates whether or not the factory is configured to produce
parsers which ignore ignorable whitespace in element content.
|
boolean | isNamespaceAware() - Indicates whether or not the factory is configured to produce
parsers which are namespace aware.
|
boolean | isValidating() - Indicates whether or not the factory is configured to produce
parsers which validate the XML content during parse.
|
DocumentBuilder | newDocumentBuilder() - Creates a new instance of a
DocumentBuilder
using the currently configured parameters.
|
static DocumentBuilderFactory | newInstance() - Obtain a new instance of a
DocumentBuilderFactory .
|
void | setAttribute(String name, Object value) - Allows the user to set specific attributes on the underlying
implementation.
|
void | setCoalescing(boolean coalescing) - Specifies that the parser produced by this code will
convert CDATA nodes to Text nodes and append it to the
adjacent (if any) text node.
|
void | setExpandEntityReferences(boolean expandEntityRef) - Specifies that the parser produced by this code will
expand entity reference nodes.
|
void | setIgnoringComments(boolean ignoreComments) - Specifies that the parser produced by this code will
ignore comments.
|
void | setIgnoringElementContentWhitespace(boolean whitespace) - Specifies that the parsers created by this factory must eliminate
whitespace in element content (sometimes known loosely as
'ignorable whitespace') when parsing XML documents (see XML Rec
2.10).
|
void | setNamespaceAware(boolean awareness) - Specifies that the parser produced by this code will
provide support for XML namespaces.
|
void | setValidating(boolean validating) - Specifies that the parser produced by this code will
validate documents as they are parsed.
|
DocumentBuilderFactory
protected DocumentBuilderFactory()
getAttribute
public Object getAttribute(String name)
throws IllegalArgumentException
Allows the user to retrieve specific attributes on the underlying
implementation.
name
- The name of the attribute.
- value The value of the attribute.
isCoalescing
public boolean isCoalescing()
Indicates whether or not the factory is configured to produce
parsers which converts CDATA nodes to Text nodes and appends it to
the adjacent (if any) Text node.
- 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.
isExpandEntityReferences
public boolean isExpandEntityReferences()
Indicates whether or not the factory is configured to produce
parsers which expand entity reference nodes.
- true if the factory is configured to produce parsers
which expand entity reference nodes; false otherwise.
isIgnoringComments
public boolean isIgnoringComments()
Indicates whether or not the factory is configured to produce
parsers which ignores comments.
- true if the factory is configured to produce parsers
which ignores comments; false otherwise.
isIgnoringElementContentWhitespace
public boolean isIgnoringElementContentWhitespace()
Indicates whether or not the factory is configured to produce
parsers which ignore ignorable whitespace in element content.
- true if the factory is configured to produce parsers
which ignore ignorable whitespace in element content;
false otherwise.
isNamespaceAware
public boolean isNamespaceAware()
Indicates whether or not the factory is configured to produce
parsers which are namespace aware.
- true if the factory is configured to produce parsers which
are namespace aware; false otherwise.
isValidating
public boolean isValidating()
Indicates whether or not the factory is configured to produce
parsers which validate the XML content during parse.
- true if the factory is configured to produce parsers
which validate the XML content during parse; false otherwise.
newInstance
public static DocumentBuilderFactory newInstance()
throws FactoryConfigurationError
Obtain a new instance of a
DocumentBuilderFactory
. This static method creates
a new factory instance.
This method uses the following ordered lookup procedure to determine
the
DocumentBuilderFactory
implementation class to
load:
-
Use the
javax.xml.parsers.DocumentBuilderFactory
system
property.
-
Use the properties file "lib/jaxp.properties" in the JRE directory.
This configuration file is in standard
java.util.Properties
format and contains the fully qualified name of the
implementation class with the key being the system property defined
above.
-
Use the Services API (as detailed in the JAR specification), if
available, to determine the classname. The Services API will look
for a classname in the file
META-INF/services/javax.xml.parsers.DocumentBuilderFactory
in jars available to the runtime.
-
Platform default
DocumentBuilderFactory
instance.
Once an application has obtained a reference to a
DocumentBuilderFactory
it can use the factory to
configure and obtain parser instances.
FactoryConfigurationError
- if the implementation is not
available or cannot be instantiated.
setAttribute
public void setAttribute(String name,
Object value)
throws IllegalArgumentException
Allows the user to set specific attributes on the underlying
implementation.
name
- The name of the attribute.value
- The value of the attribute.
setCoalescing
public void setCoalescing(boolean coalescing)
Specifies that the parser produced by this code will
convert CDATA nodes to Text nodes and append it to the
adjacent (if any) text node. By default the value of this is set to
false
coalescing
- true if the parser produced will convert CDATA nodes
to Text nodes and append it to the adjacent (if any)
text node; false otherwise.
setExpandEntityReferences
public void setExpandEntityReferences(boolean expandEntityRef)
Specifies that the parser produced by this code will
expand entity reference nodes. By default the value of this is set to
true
expandEntityRef
- true if the parser produced will expand entity
reference nodes; false otherwise.
setIgnoringComments
public void setIgnoringComments(boolean ignoreComments)
Specifies that the parser produced by this code will
ignore comments. By default the value of this is set to false
setIgnoringElementContentWhitespace
public void setIgnoringElementContentWhitespace(boolean whitespace)
Specifies that the parsers created by this factory must eliminate
whitespace in element content (sometimes known loosely as
'ignorable whitespace') when parsing XML documents (see XML Rec
2.10). Note that only whitespace which is directly contained within
element content that has an element only content model (see XML
Rec 3.2.1) will be eliminated. Due to reliance on the content model
this setting requires the parser to be in validating mode. By default
the value of this is set to false
.
whitespace
- true if the parser created must eliminate whitespace
in the element content when parsing XML documents;
false otherwise.
setNamespaceAware
public void setNamespaceAware(boolean awareness)
Specifies that the parser produced by this code will
provide support for XML namespaces. By default the value of this is set
to false
awareness
- true if the parser produced will provide support
for XML namespaces; false otherwise.
setValidating
public void setValidating(boolean validating)
Specifies that the parser produced by this code will
validate documents as they are parsed. By default the value of this
is set to false
.
validating
- true if the parser produced will validate documents
as they are parsed; false otherwise.