javax.xml.parsers
Class DocumentBuilderFactory

java.lang.Object
  extended byjavax.xml.parsers.DocumentBuilderFactory

public abstract class DocumentBuilderFactory
extends Object

Defines a factory API that enables applications to obtain a parser that produces DOM object trees from XML documents.


Constructor Summary
protected DocumentBuilderFactory()
           
 
Method Summary
abstract  Object getAttribute(String name)
          Allows the user to retrieve specific attributes on the underlying implementation.
abstract  boolean getFeature(String name)
          Get the state of the named feature.
 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.
abstract  DocumentBuilder newDocumentBuilder()
          Creates a new instance of a DocumentBuilder using the currently configured parameters.
static DocumentBuilderFactory newInstance()
          Obtain a new instance of a DocumentBuilderFactory.
abstract  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.
abstract  void setFeature(String name, boolean value)
          Set a feature for this DocumentBuilderFactory and DocumentBuilders created by this factory.
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentBuilderFactory

protected DocumentBuilderFactory()
Method Detail

newInstance

public static DocumentBuilderFactory newInstance()
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: Once an application has obtained a reference to a DocumentBuilderFactory it can use the factory to configure and obtain parser instances.

Tip for Trouble-shooting on CDC

Setting the jaxp.debug system property will cause this method to print a lot of debug messages to System.err about what it is doing and where it is looking at.

If you have problems loading DocumentBuilders, try:

 java -Djaxp.debug=1 YourProgram ....
 

Returns:
New instance of a DocumentBuilderFactory
Throws:
FactoryConfigurationError - if the implementation is not available or cannot be instantiated.

newDocumentBuilder

public abstract DocumentBuilder newDocumentBuilder()
                                            throws ParserConfigurationException
Creates a new instance of a DocumentBuilder using the currently configured parameters.

Returns:
A new instance of a DocumentBuilder.
Throws:
ParserConfigurationException - if a DocumentBuilder cannot be created which satisfies the configuration requested.

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

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

Note that "the validation" here means a validating parser as defined in the XML recommendation. In other words, it essentially just controls the DTD validation.

Parameters:
validating - true if the parser produced will validate documents as they are parsed; false otherwise.

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.

Parameters:
whitespace - true if the parser created must eliminate whitespace in the element content when parsing XML documents; 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

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

Parameters:
ignoreComments - boolean value to ignore comments during processing

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

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

isNamespaceAware

public boolean isNamespaceAware()
Indicates whether or not the factory is configured to produce parsers which are namespace aware.

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

Returns:
true if the factory is configured to produce parsers which validate the XML content during parse; false otherwise.

isIgnoringElementContentWhitespace

public boolean isIgnoringElementContentWhitespace()
Indicates whether or not the factory is configured to produce parsers which ignore ignorable whitespace in element content.

Returns:
true if the factory is configured to produce parsers which ignore ignorable whitespace in element content; false otherwise.

isExpandEntityReferences

public boolean isExpandEntityReferences()
Indicates whether or not the factory is configured to produce parsers which expand entity reference nodes.

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

Returns:
true if the factory is configured to produce parsers which ignores comments; false otherwise.

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.

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.

setAttribute

public abstract void setAttribute(String name,
                                  Object value)
                           throws IllegalArgumentException
Allows the user to set specific attributes on the underlying implementation.

Parameters:
name - The name of the attribute.
value - The value of the attribute.
Throws:
IllegalArgumentException - thrown if the underlying implementation doesn't recognize the attribute.

getAttribute

public abstract Object getAttribute(String name)
                             throws IllegalArgumentException
Allows the user to retrieve specific attributes on the underlying implementation.

Parameters:
name - The name of the attribute.
Returns:
value The value of the attribute.
Throws:
IllegalArgumentException - thrown if the underlying implementation doesn't recognize the attribute.

setFeature

public abstract void setFeature(String name,
                                boolean value)
                         throws ParserConfigurationException

Set a feature for this DocumentBuilderFactory and DocumentBuilders created by this factory.

Feature names are fully qualified URIs. Implementations may define their own features. An ParserConfigurationException is thrown if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support the feature. It is possible for an DocumentBuilderFactory to expose a feature value but be unable to change its state. A null feature name parameter causes the XML reader to throw a NullPointerException.

All implementations are required to support the XMLConstants.FEATURE_SECURE_PROCESSING feature. When the feature is:

Parameters:
name - Feature name.
value - Is feature state true or false.
Throws:
ParserConfigurationException - if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support this feature.
NullPointerException - If the name parameter is null.

getFeature

public abstract boolean getFeature(String name)
                            throws ParserConfigurationException

Get the state of the named feature.

Feature names are fully qualified URIs. Implementations may define their own features. A ParserConfigurationException is thrown if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support the feature. It is possible for an DocumentBuilderFactory to expose a feature value but be unable to change its state. A NullPointerException is thrown if the feature name parameter is null.

Parameters:
name - Feature name.
Returns:
State of the named feature.
Throws:
ParserConfigurationException - if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support this feature.


Copyright © 2006,2007 Sun Microsystems, Inc. All rights reserved. See the Copyright Notice for details.