Top Description Fields Constructors Methods
org.dom4j.dom

public Class DOMDocument

extends DefaultDocument
implements Document
Class Inheritance
All Implemented Interfaces
org.w3c.dom.Document, org.w3c.dom.Node
Imports
org.dom4j.*, org.dom4j.tree.DefaultDocument, org.w3c.dom.*, .Comment, .Document, .DocumentType, .Element, .Node, .ProcessingInstruction, .Text, java.util.ArrayList

DOMDocument implements an XML document which supports the W3C DOM API.

Author
James Strachan
Version
$Revision: 1.17 $

Field Summary

Modifier and TypeField and Description
private static final DOMDocumentFactory
DOCUMENT_FACTORY

Hides org.dom4j.tree.AbstractNode.DOCUMENT_FACTORY.

The DocumentFactory instance used by default

Constructor Summary

AccessConstructor and Description
public
public
public
DOMDocument(DOMElement rootElement)

public
public
DOMDocument(DOMElement rootElement, DOMDocumentType docType)

public
DOMDocument(String name, DOMElement rootElement, DOMDocumentType docType)

Method Summary

Modifier and TypeMethod and Description
public Node
adoptNode(Node
The node to move into this document.
source
)

Implements org.w3c.dom.Document.adoptNode.

Attempts to adopt a node from another document to this document.
public Node
appendChild(Node
The node to add.If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node
newChild
)

Implements org.w3c.dom.Node.appendChild.

Adds the node newChild to the end of the list of children of this node.
private void
public Node
cloneNode(boolean
If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
deep
)

Implements org.w3c.dom.Node.cloneNode.

Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
public short
compareDocumentPosition(Node
The node to compare against the reference node.
other
)

Implements org.w3c.dom.Node.compareDocumentPosition.

Compares the reference node, i.e. the node on which this method is being called, with a node, i.e. the one passed as a parameter, with regard to their position in the document and according to the document order.
public Attr
createAttribute(String
The name of the attribute.
name
)

Implements org.w3c.dom.Document.createAttribute.

Creates an Attr of the given name.
public Attr
createAttributeNS(String
The namespace URI of the attribute to create.
namespaceURI
,
String
The qualified name of the attribute to instantiate.
qualifiedName
)

Implements org.w3c.dom.Document.createAttributeNS.

Creates an attribute of the given qualified name and namespace URI.
public CDATASection
createCDATASection(String
The data for the CDATASection contents.
data
)

Implements org.w3c.dom.Document.createCDATASection.

Creates a CDATASection node whose value is the specified string.
public Comment
createComment(String
The data for the node.
data
)

Implements org.w3c.dom.Document.createComment.

Creates a Comment node given the specified string.
public DocumentFragment
createDocumentFragment()

Implements org.w3c.dom.Document.createDocumentFragment.

Creates an empty DocumentFragment object.
public Element
createElement(String
The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup by the DOM implementation.
name
)

Implements org.w3c.dom.Document.createElement.

Creates an element of the type specified.
public Element
createElementNS(String
The namespace URI of the element to create.
namespaceURI
,
String
The qualified name of the element type to instantiate.
qualifiedName
)

Implements org.w3c.dom.Document.createElementNS.

Creates an element of the given qualified name and namespace URI.
public EntityReference
createEntityReference(String
The name of the entity to reference.Unlike Document.createElementNS or Document.createAttributeNS, no namespace well-formed checking is done on the entity name. Applications should invoke Document.normalizeDocument() with the parameter " namespaces" set to true in order to ensure that the entity name is namespace well-formed.
name
)

Implements org.w3c.dom.Document.createEntityReference.

Creates an EntityReference object.
public ProcessingInstruction
createProcessingInstruction(String
The target part of the processing instruction.Unlike Document.createElementNS or Document.createAttributeNS, no namespace well-formed checking is done on the target name. Applications should invoke Document.normalizeDocument() with the parameter " namespaces" set to true in order to ensure that the target name is namespace well-formed.
target
,
String
The data for the node.
data
)

Implements org.w3c.dom.Document.createProcessingInstruction.

Creates a ProcessingInstruction node given the specified name and data strings.
public Text
createTextNode(String
The data for the node.
data
)

Implements org.w3c.dom.Document.createTextNode.

Creates a Text node given the specified string.
public NamedNodeMap
getAttributes()

Implements org.w3c.dom.Node.getAttributes.

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
public String
getBaseURI()

Implements org.w3c.dom.Node.getBaseURI.

The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.
public NodeList
getChildNodes()

Implements org.w3c.dom.Node.getChildNodes.

A NodeList that contains all children of this node.
public DocumentType
getDoctype()

Implements org.w3c.dom.Document.getDoctype.

The Document Type Declaration (see DocumentType) associated with this document.
public Element
getDocumentElement()

Implements org.w3c.dom.Document.getDocumentElement.

This is a convenience attribute that allows direct access to the child node that is the document element of the document.
protected DocumentFactory
public String
getDocumentURI()

Implements org.w3c.dom.Document.getDocumentURI.

The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument.
public DOMConfiguration
getDomConfig()

Implements org.w3c.dom.Document.getDomConfig.

The configuration used when Document.normalizeDocument() is invoked.
public Element
getElementById(String
The unique id value for an element.
elementId
)

Implements org.w3c.dom.Document.getElementById.

Returns the Element that has an ID attribute with the given value.
public NodeList
getElementsByTagName(String
The name of the tag to match on. The special value "*" matches all tags. For XML, the tagname parameter is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use.
name
)

Implements org.w3c.dom.Document.getElementsByTagName.

Returns a NodeList of all the Elements in document order with a given tag name and are contained in the document.
public NodeList
getElementsByTagNameNS(String
The namespace URI of the elements to match on. The special value "*" matches all namespaces.
namespace
,
String
The local name of the elements to match on. The special value "*" matches all local names.
name
)

Implements org.w3c.dom.Document.getElementsByTagNameNS.

Returns a NodeList of all the Elements with a given local name and namespace URI in document order.
public Object
getFeature(String
The name of the feature requested. Note that any plus sign "+" prepended to the name of the feature will be ignored since it is not significant in the context of this method.
feature
,
String
This is the version number of the feature to test.
version
)

Implements org.w3c.dom.Node.getFeature.

This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in .
public Node
getFirstChild()

Implements org.w3c.dom.Node.getFirstChild.

The first child of this node.
public DOMImplementation
getImplementation()

Implements org.w3c.dom.Document.getImplementation.

The DOMImplementation object that handles this document.
public String
getInputEncoding()

Implements org.w3c.dom.Document.getInputEncoding.

An attribute specifying the encoding used for this document at the time of the parsing.
public Node
getLastChild()

Implements org.w3c.dom.Node.getLastChild.

The last child of this node.
public String
getLocalName()

Implements org.w3c.dom.Node.getLocalName.

Returns the local part of the qualified name of this node.
public String
getNamespaceURI()

Implements org.w3c.dom.Node.getNamespaceURI.

The namespace URI of this node, or null if it is unspecified (see ).
public Node
getNextSibling()

Implements org.w3c.dom.Node.getNextSibling.

The node immediately following this node.
public String
getNodeName()

Implements org.w3c.dom.Node.getNodeName.

The name of this node, depending on its type; see the table above.
public String
getNodeValue()

Implements org.w3c.dom.Node.getNodeValue.

The value of this node, depending on its type; see the table above.
public Document
getOwnerDocument()

Implements org.w3c.dom.Node.getOwnerDocument.

The Document object associated with this node.
public Node
getParentNode()

Implements org.w3c.dom.Node.getParentNode.

The parent of this node.
public String
getPrefix()

Implements org.w3c.dom.Node.getPrefix.

The namespace prefix of this node, or null if it is unspecified.
public Node
getPreviousSibling()

Implements org.w3c.dom.Node.getPreviousSibling.

The node immediately preceding this node.
public boolean
getStrictErrorChecking()

Implements org.w3c.dom.Document.getStrictErrorChecking.

An attribute specifying whether error checking is enforced or not.
public String
getTextContent()

Implements org.w3c.dom.Node.getTextContent.

This attribute returns the text content of this node and its descendants.
public Object
getUserData(String
The key the object is associated to.
key
)

Implements org.w3c.dom.Node.getUserData.

Retrieves the object associated to a key on a this node.
public String
getXmlEncoding()

Implements org.w3c.dom.Document.getXmlEncoding.

An attribute specifying, as part of the XML declaration, the encoding of this document.
public boolean
getXmlStandalone()

Implements org.w3c.dom.Document.getXmlStandalone.

An attribute specifying, as part of the XML declaration, whether this document is standalone.
public String
getXmlVersion()

Implements org.w3c.dom.Document.getXmlVersion.

An attribute specifying, as part of the XML declaration, the version number of this document.
public boolean
hasAttributes()

Implements org.w3c.dom.Node.hasAttributes.

Returns whether this node (if it is an element) has any attributes.
public boolean
hasChildNodes()

Implements org.w3c.dom.Node.hasChildNodes.

Returns whether this node has any children.
public Node
importNode(Node
The node to import.
importedNode
,
boolean
If true, recursively import the subtree under the specified node; if false, import only the node itself, as explained above. This has no effect on nodes that cannot have any children, and on Attr, and EntityReference nodes.
deep
)

Implements org.w3c.dom.Document.importNode.

Imports a node from another document to this document, without altering or removing the source node from the original document; this method creates a new copy of the source node.
private void
init()

public Node
insertBefore(Node
The node to insert.
newChild
,
Node
The reference node, i.e., the node before which the new node must be inserted.
refChild
)

Implements org.w3c.dom.Node.insertBefore.

Inserts the node newChild before the existing child node refChild.
public boolean
isDefaultNamespace(String
The namespace URI to look for.
namespaceURI
)

Implements org.w3c.dom.Node.isDefaultNamespace.

This method checks if the specified namespaceURI is the default namespace or not.
public boolean
isEqualNode(Node
The node to compare equality with.
other
)

Implements org.w3c.dom.Node.isEqualNode.

Tests whether two nodes are equal.
public boolean
isSameNode(Node
The node to test against.
other
)

Implements org.w3c.dom.Node.isSameNode.

Returns whether this node is the same node as the given one.
public boolean
isSupported(String
The name of the feature to test.
feature
,
String
This is the version number of the feature to test.
version
)

Implements org.w3c.dom.Node.isSupported.

Tests whether the DOM implementation implements a specific feature and that feature is supported by this node, as specified in .
public String
lookupNamespaceURI(String
The prefix to look for. If this parameter is null, the method will return the default namespace URI if any.
prefix
)

Implements org.w3c.dom.Node.lookupNamespaceURI.

Look up the namespace URI associated to the given prefix, starting from this node.
public String
lookupPrefix(String
The namespace URI to look for.
namespaceURI
)

Implements org.w3c.dom.Node.lookupPrefix.

Look up the prefix associated to the given namespace URI, starting from this node.
public void
normalizeDocument()

Implements org.w3c.dom.Document.normalizeDocument.

This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form.
public Node
removeChild(Node
The node being removed.
oldChild
)

Implements org.w3c.dom.Node.removeChild.

Removes the child node indicated by oldChild from the list of children, and returns it.
public Node
renameNode(Node
The node to rename.
n
,
String
The new namespace URI.
namespaceURI
,
String
The new qualified name.
qualifiedName
)

Implements org.w3c.dom.Document.renameNode.

Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE.
public Node
replaceChild(Node
The new node to put in the child list.
newChild
,
Node
The node being replaced in the list.
oldChild
)

Implements org.w3c.dom.Node.replaceChild.

Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
public void
setDocumentURI(String documentURI)

Implements org.w3c.dom.Document.setDocumentURI.

The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument.
public void
setNodeValue(String nodeValue)

Implements org.w3c.dom.Node.setNodeValue.

The value of this node, depending on its type; see the table above.
public void
setPrefix(String prefix)

Implements org.w3c.dom.Node.setPrefix.

The namespace prefix of this node, or null if it is unspecified.
public void
setStrictErrorChecking(boolean strictErrorChecking)

Implements org.w3c.dom.Document.setStrictErrorChecking.

An attribute specifying whether error checking is enforced or not.
public void
setTextContent(String textContent)

Implements org.w3c.dom.Node.setTextContent.

This attribute returns the text content of this node and its descendants.
public Object
setUserData(String
The key to associate the object to.
key
,
Object
The object to associate to the given key, or null to remove any existing association to that key.
data
,
UserDataHandler
The handler to associate to that key, or null.
handler
)

Implements org.w3c.dom.Node.setUserData.

Associate an object to a key on this node.
public void
setXmlStandalone(boolean xmlStandalone)

Implements org.w3c.dom.Document.setXmlStandalone.

An attribute specifying, as part of the XML declaration, whether this document is standalone.
public void
setXmlVersion(String xmlVersion)

Implements org.w3c.dom.Document.setXmlVersion.

An attribute specifying, as part of the XML declaration, the version number of this document.
public boolean
supports(String feature, String version)

Inherited from org.dom4j.tree.DefaultDocument:
addDocTypeaddNodeaddNodeclearContentclonecontentListgetDocTypegetEntityResolvergetNamegetRootElementgetXMLEncodingprocessingInstructionprocessingInstructionsprocessingInstructionsremoveNoderemoveProcessingInstructionrootElementAddedsetContentsetDocTypesetDocumentFactorysetEntityResolversetName