Top Description Fields Constructors Methods
org.dom4j.tree

public abstract Class AbstractDocument

extends AbstractBranch
implements Document
Class Inheritance
All Implemented Interfaces
org.dom4j.Document, org.dom4j.Branch, org.dom4j.Node, java.lang.Cloneable
Known Direct Subclasses
org.dom4j.tree.DefaultDocument
Imports
org.dom4j.*, org.dom4j.io.OutputFormat, .XMLWriter, java.io.IOException, .StringWriter, .Writer, java.util.List, .Map

AbstractDocument is an abstract base class for tree implementors to use for implementation inheritence.

Author
James Strachan
Version
$Revision: 1.33 $

Field Summary

Modifier and TypeField and Description
protected String
encoding

The encoding of this document as stated in the XML declaration

Inherited from org.dom4j.tree.AbstractBranch:
DEFAULT_CONTENT_LIST_SIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
accept(Visitor
Visitor is the visitor.
visitor
)

Implements org.dom4j.Node.accept.

accept method is the Visitor Pattern method.

public void
add(Element
is the element to be added
element
)

Overrides org.dom4j.tree.AbstractBranch.add.

Implements org.dom4j.Branch.add.

Adds the given Element to this branch.
public Document
addComment(String
is the text for the Comment node.
comment
)

Implements org.dom4j.Document.addComment.

Adds a new Comment node with the given text to this branch.
public Element
addElement(String
is the name for the Element node.
name
)

Overrides org.dom4j.tree.AbstractBranch.addElement.

Implements org.dom4j.Branch.addElement.

Adds a new Element node with the given name to this branch and returns a reference to the new node.
public Element
addElement(String
is the fully qualified name of the Element
qualifiedName
,
String
is the URI of the namespace to use
namespaceURI
)

Overrides org.dom4j.tree.AbstractBranch.addElement.

Implements org.dom4j.Branch.addElement.

Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.
public Element
addElement(QName
is the qualified name for the Element node.
qName
)

Overrides org.dom4j.tree.AbstractBranch.addElement.

Implements org.dom4j.Branch.addElement.

Adds a new Element node with the given QNameto this branch and returns a reference to the new node.
public Document
addProcessingInstruction(String
is the target of the processing instruction
target
,
String
is the textual data (key/value pairs) of the processing instruction
data
)

Implements org.dom4j.Document.addProcessingInstruction.

Adds a processing instruction for the given target
public Document
addProcessingInstruction(String
is the target of the processing instruction
target
,
Map<String, String>
is a Map of the key / value pairs of the processing instruction
data
)

Implements org.dom4j.Document.addProcessingInstruction.

Adds a processing instruction for the given target
public String
asXML()

Implements org.dom4j.Node.asXML.

asXML returns the textual XML representation of this node.

public Node
asXPathResult(Element
DOCUMENT ME!
parent
)

Overrides org.dom4j.tree.AbstractNode.asXPathResult.

Implements org.dom4j.Node.asXPathResult.

asXPathResult returns a version of this node which is capable of being an XPath result.

protected void
protected void
childAdded(Node
DOCUMENT ME!
node
)

Implements abstract org.dom4j.tree.AbstractBranch.childAdded.

Called when a new child node has been added to me to allow any parent relationships to be created or events to be fired.
protected void
childRemoved(Node
DOCUMENT ME!
node
)

Implements abstract org.dom4j.tree.AbstractBranch.childRemoved.

Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.
public Document
getDocument()

Overrides org.dom4j.tree.AbstractNode.getDocument.

Implements org.dom4j.Node.getDocument.

getDocument returns the Document that this Node is part of if this node supports the parent relationship.

public short
getNodeType()

Overrides org.dom4j.tree.AbstractNode.getNodeType.

Implements org.dom4j.Node.getNodeType.

Returns the code according to the type of node.
public String
getPath(Element
is the parent context from which the relative path should start. If the context is null or the context is not an ancestor of this node then the path will be absolute and start from the document and so begin with the '/' character.
context
)

Implements org.dom4j.Node.getPath.

Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c.
public String
getStringValue()

Overrides org.dom4j.tree.AbstractNode.getStringValue.

Implements org.dom4j.Node.getStringValue.

Returns the XPath string-value of this node.
public String
getUniquePath(Element
is the parent context from which the path should start. If the context is null or the context is not an ancestor of this node then the path will start from the document and so begin with the '/' character.
context
)

Implements org.dom4j.Node.getUniquePath.

Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node.

public String
getXMLEncoding()

Implements org.dom4j.Document.getXMLEncoding.

Return the encoding of this document, as part of the XML declaration This is null when unspecified or when it is not known (such as when the Document was created in memory) or when the implementation does not support this operation.
public void
normalize()

Implements org.dom4j.Branch.normalize.

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
public boolean
remove(Element
is the element to be removed
element
)

Overrides org.dom4j.tree.AbstractBranch.remove.

Implements org.dom4j.Branch.remove.

Removes the given Element if the node is an immediate child of this branch.
protected abstract void
rootElementAdded(Element
DOCUMENT ME!
rootElement
)

Called to set the root element variable

public void
setRootElement(Element
the new root element for this document
rootElement
)

Implements org.dom4j.Document.setRootElement.

Sets the root element for this document
public void
setXMLEncoding(String
the encoding of the document
enc
)

Implements org.dom4j.Document.setXMLEncoding.

Sets the encoding of this document as it will appear in the XML declaration part of the document.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(Writer
is the Writer to output the XML to
out
)

Overrides org.dom4j.tree.AbstractNode.write.

Implements org.dom4j.Node.write.

write writes this node as the default XML notation for this node.

Inherited from org.dom4j.tree.AbstractBranch:
addaddaddaddElementaddNodeaddNodeappendContentcontentcontentListcontentRemovedcreateContentListcreateContentListcreateEmptyListcreateResultListcreateSingleResultListelementByIDelementIDgetContentAsStringValuegetContentAsTextgetTextgetTextTrimhasContentindexOfinvalidNodeTypeAddExceptionisReadOnlynodenodeCountnodeIteratorremoveremoveremoveremoveNodesetProcessingInstructions

Field Detail

encodingback to summary
protected String encoding

The encoding of this document as stated in the XML declaration

Constructor Detail

AbstractDocumentback to summary
public AbstractDocument()

Method Detail

acceptback to summary
public void accept(Visitor visitor)

Implements org.dom4j.Node.accept.

accept method is the Visitor Pattern method.

Parameters
visitor:Visitor

Visitor is the visitor.

addback to summary
public void add(Element element)

Overrides org.dom4j.tree.AbstractBranch.add.

Implements org.dom4j.Branch.add.

Doc from org.dom4j.Branch.add.

Adds the given Element to this branch. If the given node already has a parent defined then an IllegalAddException will be thrown.

Parameters
element:Element

is the element to be added

addCommentback to summary
public Document addComment(String comment)

Implements org.dom4j.Document.addComment.

Doc from org.dom4j.Document.addComment.

Adds a new Comment node with the given text to this branch.

Parameters
comment:String

is the text for the Comment node.

Returns:Document

this Document instance.

addElementback to summary
public Element addElement(String name)

Overrides org.dom4j.tree.AbstractBranch.addElement.

Implements org.dom4j.Branch.addElement.

Doc from org.dom4j.Branch.addElement.

Adds a new Element node with the given name to this branch and returns a reference to the new node.

Parameters
name:String

is the name for the Element node.

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(String qualifiedName, String namespaceURI)

Overrides org.dom4j.tree.AbstractBranch.addElement.

Implements org.dom4j.Branch.addElement.

Doc from org.dom4j.Branch.addElement.

Adds a new Element node with the given qualified name and namespace URI to this branch and returns a reference to the new node.

Parameters
qualifiedName:String

is the fully qualified name of the Element

namespaceURI:String

is the URI of the namespace to use

Returns:Element

the newly added Element node.

addElementback to summary
public Element addElement(QName qName)

Overrides org.dom4j.tree.AbstractBranch.addElement.

Implements org.dom4j.Branch.addElement.

Doc from org.dom4j.Branch.addElement.

Adds a new Element node with the given QNameto this branch and returns a reference to the new node.

Parameters
qName:QName

is the qualified name for the Element node.

Returns:Element

the newly added Element node.

addProcessingInstructionback to summary
public Document addProcessingInstruction(String target, String data)

Implements org.dom4j.Document.addProcessingInstruction.

Doc from org.dom4j.Document.addProcessingInstruction.

Adds a processing instruction for the given target

Parameters
target:String

is the target of the processing instruction

data:String

is the textual data (key/value pairs) of the processing instruction

Returns:Document

this Document instance.

addProcessingInstructionback to summary
public Document addProcessingInstruction(String target, Map<String, String> data)

Implements org.dom4j.Document.addProcessingInstruction.

Doc from org.dom4j.Document.addProcessingInstruction.

Adds a processing instruction for the given target

Parameters
target:String

is the target of the processing instruction

data:Map<String, String>

is a Map of the key / value pairs of the processing instruction

Returns:Document

this Document instance.

asXMLback to summary
public String asXML()

Implements org.dom4j.Node.asXML.

Doc from org.dom4j.Node.asXML.

asXML returns the textual XML representation of this node.

Returns:String

the XML representation of this node

asXPathResultback to summary
public Node asXPathResult(Element parent)

Overrides org.dom4j.tree.AbstractNode.asXPathResult.

Implements org.dom4j.Node.asXPathResult.

Doc from org.dom4j.Node.asXPathResult.

asXPathResult returns a version of this node which is capable of being an XPath result. The result of an XPath expression should always support the parent relationship, whether the original XML tree was singly or doubly linked. If the node does not support the parent relationship then a new node will be created which is linked to its parent and returned.

Parameters
parent:Element

DOCUMENT ME!

Returns:Node

a Node which supports the parent relationship

checkAddElementAllowedback to summary
protected void checkAddElementAllowed(Element element)
childAddedback to summary
protected void childAdded(Node node)

Implements abstract org.dom4j.tree.AbstractBranch.childAdded.

Doc from org.dom4j.tree.AbstractBranch.childAdded.

Called when a new child node has been added to me to allow any parent relationships to be created or events to be fired.

Parameters
node:Node

DOCUMENT ME!

childRemovedback to summary
protected void childRemoved(Node node)

Implements abstract org.dom4j.tree.AbstractBranch.childRemoved.

Doc from org.dom4j.tree.AbstractBranch.childRemoved.

Called when a child node has been removed to allow any parent relationships to be deleted or events to be fired.

Parameters
node:Node

DOCUMENT ME!

getDocumentback to summary
public Document getDocument()

Overrides org.dom4j.tree.AbstractNode.getDocument.

Implements org.dom4j.Node.getDocument.

Doc from org.dom4j.Node.getDocument.

getDocument returns the Document that this Node is part of if this node supports the parent relationship.

This method is an optional feature and may not be supported for all Node implementations.

Returns:Document

the document of this node or null if this feature is not supported or the node is not associated with a Document

getNodeTypeback to summary
public short getNodeType()

Overrides org.dom4j.tree.AbstractNode.getNodeType.

Implements org.dom4j.Node.getNodeType.

Doc from org.dom4j.Node.getNodeType.

Returns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.

Returns:short

a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE

getPathback to summary
public String getPath(Element context)

Implements org.dom4j.Node.getPath.

Doc from org.dom4j.Node.getPath.

Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c. No indexing will be used to restrict the path if multiple elements with the same name occur on the path.

Parameters
context:Element

is the parent context from which the relative path should start. If the context is null or the context is not an ancestor of this node then the path will be absolute and start from the document and so begin with the '/' character.

Returns:String

the XPath expression relative to the given context which will return a nodeset containing at least this node.

getStringValueback to summary
public String getStringValue()

Overrides org.dom4j.tree.AbstractNode.getStringValue.

Implements org.dom4j.Node.getStringValue.

Doc from org.dom4j.Node.getStringValue.

Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .

Returns:String

the text from all the child Text and Element nodes appended together.

getUniquePathback to summary
public String getUniquePath(Element context)

Implements org.dom4j.Node.getUniquePath.

Doc from org.dom4j.Node.getUniquePath.

Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.

Parameters
context:Element

is the parent context from which the path should start. If the context is null or the context is not an ancestor of this node then the path will start from the document and so begin with the '/' character.

Returns:String

the XPath expression relative to the given context which will return a nodeset containing just this node.

getXMLEncodingback to summary
public String getXMLEncoding()

Implements org.dom4j.Document.getXMLEncoding.

Doc from org.dom4j.Document.getXMLEncoding.

Return the encoding of this document, as part of the XML declaration This is null when unspecified or when it is not known (such as when the Document was created in memory) or when the implementation does not support this operation. The way this encoding is retrieved also depends on the way the XML source is parsed. For instance, if the SAXReader is used and if the underlying XMLReader implementation support the org.xml.sax.ext.Locator2 interface, the result returned by this method is specified by the getEncoding() method of that interface.

Returns:String

The encoding of this document, as stated in the XML declaration, or null if unknown.

normalizeback to summary
public void normalize()

Implements org.dom4j.Branch.normalize.

Doc from org.dom4j.Branch.normalize.

Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

removeback to summary
public boolean remove(Element element)

Overrides org.dom4j.tree.AbstractBranch.remove.

Implements org.dom4j.Branch.remove.

Doc from org.dom4j.Branch.remove.

Removes the given Element if the node is an immediate child of this branch. If the given node is not an immediate child of this branch then the Node#detach()method should be used instead.

Parameters
element:Element

is the element to be removed

Returns:boolean

true if the element was removed

rootElementAddedback to summary
protected abstract void rootElementAdded(Element rootElement)

Called to set the root element variable

Parameters
rootElement:Element

DOCUMENT ME!

setRootElementback to summary
public void setRootElement(Element rootElement)

Implements org.dom4j.Document.setRootElement.

Doc from org.dom4j.Document.setRootElement.

Sets the root element for this document

Parameters
rootElement:Element

the new root element for this document

setXMLEncodingback to summary
public void setXMLEncoding(String enc)

Implements org.dom4j.Document.setXMLEncoding.

Doc from org.dom4j.Document.setXMLEncoding.

Sets the encoding of this document as it will appear in the XML declaration part of the document.

Parameters
enc:String

the encoding of the document

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

writeback to summary
public void write(Writer out) throws IOException

Overrides org.dom4j.tree.AbstractNode.write.

Implements org.dom4j.Node.write.

Doc from org.dom4j.Node.write.

write writes this node as the default XML notation for this node. If you wish to control the XML output (such as for pretty printing, changing the indentation policy etc.) then please use org.dom4j.io.XMLWriter or its derivations.

Parameters
out:Writer

is the Writer to output the XML to

Exceptions
IOException:
DOCUMENT ME!