Top Description Fields Constructors Methods
org.dom4j.tree

public abstract Class AbstractNode

extends Object
implements Node, Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable, org.dom4j.Node
Known Direct Subclasses
org.dom4j.tree.AbstractProcessingInstruction, org.dom4j.Namespace, org.dom4j.tree.AbstractAttribute, org.dom4j.tree.AbstractBranch, org.dom4j.tree.AbstractCharacterData, org.dom4j.tree.AbstractDocumentType, org.dom4j.tree.AbstractEntity
Imports
org.dom4j.*, org.dom4j.rule.Pattern, java.io.IOException, .Serializable, .Writer, java.util.List

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

Author
James Strachan
Version
$Revision: 1.31 $

Field Summary

Modifier and TypeField and Description
private static final DocumentFactory
DOCUMENT_FACTORY

The DocumentFactory instance used by default

protected static final String[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Node
asXPathResult(Element
DOCUMENT ME!
parent
)

Implements org.dom4j.Node.asXPathResult.

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

public Object
clone()

Overrides java.lang.Object.clone.

Implements org.dom4j.Node.clone.

clone will return a deep clone or if this node is read-only then clone will return the same instance.

public Pattern
createPattern(String patternText)

public XPath
createXPath(String
is the XPath expression to be evaluated
xpathExpression
)

Implements org.dom4j.Node.createXPath.

createXPath creates an XPath object for the given xpathExpression.

public NodeFilter
protected Node
public Node
detach()

Implements org.dom4j.Node.detach.

Removes this node from its parent if there is one.

public Document
getDocument()

Implements org.dom4j.Node.getDocument.

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

protected DocumentFactory
public String
getName()

Implements org.dom4j.Node.getName.

getName returns the name of this node.

public short
getNodeType()

Implements org.dom4j.Node.getNodeType.

Returns the code according to the type of node.
public String
public Element
getParent()

Implements org.dom4j.Node.getParent.

getParent returns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.

public String
getPath()

Implements org.dom4j.Node.getPath.

Returns the XPath expression which will return a node set containing the given node such as /a/b/@c.

public String
getStringValue()

Implements org.dom4j.Node.getStringValue.

Returns the XPath string-value of this node.
public String
getText()

Implements org.dom4j.Node.getText.

Returns the text of this node.

public String
getUniquePath()

Implements org.dom4j.Node.getUniquePath.

Returns the XPath expression which will return a nodeset of one node which is the current node.

public boolean
hasContent()

Implements org.dom4j.Node.hasContent.

hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.

public boolean
isReadOnly()

Implements org.dom4j.Node.isReadOnly.

isReadOnly returns true if this node is read only and cannot be modified.

public boolean
matches(String
is an XPath expression
patternText
)

Implements org.dom4j.Node.matches.

matches returns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.

public Number
numberValueOf(String
is the XPath expression to be evaluated
xpathExpression
)

Implements org.dom4j.Node.numberValueOf.

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.

public List<Node>
selectNodes(String
is the XPath expression to be evaluated
xpathExpression
)

Implements org.dom4j.Node.selectNodes.

selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.

public List<Node>
selectNodes(String
is the XPath expression to be evaluated
xpathExpression
,
String
is the XPath expression used to compare the results by for sorting
comparisonXPathExpression
)

Implements org.dom4j.Node.selectNodes.

selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.

public List<Node>
selectNodes(String
is the XPath expression to be evaluated
xpathExpression
,
String
is the XPath expression used to compare the results by for sorting
comparisonXPathExpression
,
boolean
if this parameter is true then duplicate values (using the comparisonXPathExpression) are removed from the result List.
removeDuplicates
)

Implements org.dom4j.Node.selectNodes.

selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.

public Object
selectObject(String
is the XPath expression to be evaluated
xpathExpression
)

Implements org.dom4j.Node.selectObject.

selectObject evaluates an XPath expression and returns the result as an Object.

public Node
selectSingleNode(String
is the XPath expression to be evaluated
xpathExpression
)

Implements org.dom4j.Node.selectSingleNode.

selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.

public void
setDocument(Document
is the new document of this node.
document
)

Implements org.dom4j.Node.setDocument.

setDocument sets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.

public void
setName(String
is the new name of this node
name
)

Implements org.dom4j.Node.setName.

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

public void
setParent(Element
is the new parent of this node.
parent
)

Implements org.dom4j.Node.setParent.

setParent sets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.

public void
setText(String
is the new textual value of this node
text
)

Implements org.dom4j.Node.setText.

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

public boolean
supportsParent()

Implements org.dom4j.Node.supportsParent.

supportsParent returns true if this node supports the parent relationship.

public String
valueOf(String
is the XPath expression to be evaluated
xpathExpression
)

Implements org.dom4j.Node.valueOf.

valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.

public void
write(Writer
is the Writer to output the XML to
writer
)

Implements org.dom4j.Node.write.

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

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DOCUMENT_FACTORYback to summary
private static final DocumentFactory DOCUMENT_FACTORY

The DocumentFactory instance used by default

NODE_TYPE_NAMESback to summary
protected static final String[] NODE_TYPE_NAMES

Constructor Detail

AbstractNodeback to summary
public AbstractNode()

Method Detail

asXPathResultback to summary
public Node asXPathResult(Element parent)

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

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Implements org.dom4j.Node.clone.

Doc from org.dom4j.Node.clone.

clone will return a deep clone or if this node is read-only then clone will return the same instance.

Returns:Object

a deep clone of myself or myself if I am read only.

createPatternback to summary
public Pattern createPattern(String patternText)
createXPathback to summary
public XPath createXPath(String xpathExpression)

Implements org.dom4j.Node.createXPath.

Doc from org.dom4j.Node.createXPath.

createXPath creates an XPath object for the given xpathExpression. The XPath object allows the variable context to be specified.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

Returns:XPath

an XPath object represeting the given expression

createXPathFilterback to summary
public NodeFilter createXPathFilter(String patternText)
createXPathResultback to summary
protected Node createXPathResult(Element parent)
detachback to summary
public Node detach()

Implements org.dom4j.Node.detach.

Doc from org.dom4j.Node.detach.

Removes this node from its parent if there is one. If this node is the root element of a document then it is removed from the document as well.

This method is useful if you want to remove a node from its source document and add it to another document. For example

Node node = ...; Element someOtherElement = ...; someOtherElement.add( node.detach() );
Returns:Node

the node that has been removed from its parent node if any and its document if any.

getDocumentback to summary
public Document 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

getDocumentFactoryback to summary
protected DocumentFactory getDocumentFactory()
getNameback to summary
public String getName()

Implements org.dom4j.Node.getName.

Doc from org.dom4j.Node.getName.

getName returns the name of this node. This is the XML local name of the element, attribute, entity or processing instruction. For CDATA and Text nodes this method will return null.

Returns:String

the XML name of this node

getNodeTypeback to summary
public short 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

getNodeTypeNameback to summary
public String getNodeTypeName()

Implements org.dom4j.Node.getNodeTypeName.

Doc from org.dom4j.Node.getNodeTypeName.

DOCUMENT ME!

Returns:String

the name of the type of node such as "Document", "Element", "Attribute" or "Text"

getParentback to summary
public Element getParent()

Implements org.dom4j.Node.getParent.

Doc from org.dom4j.Node.getParent.

getParent returns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.

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

Returns:Element

the parent of this node or null if it is the root of the tree or the parent relationship is not supported.

getPathback to summary
public String getPath()

Implements org.dom4j.Node.getPath.

Doc from org.dom4j.Node.getPath.

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

Returns:String

the XPath expression which will return a nodeset containing at least this node.

getStringValueback to summary
public String 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.

getTextback to summary
public String getText()

Implements org.dom4j.Node.getText.

Doc from org.dom4j.Node.getText.

Returns the text of this node.

Returns:String

the text for this node.

getUniquePathback to summary
public String getUniquePath()

Implements org.dom4j.Node.getUniquePath.

Doc from org.dom4j.Node.getUniquePath.

Returns the XPath expression 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.

Returns:String

the XPath expression which will return a nodeset containing just this node.

hasContentback to summary
public boolean hasContent()

Implements org.dom4j.Node.hasContent.

Doc from org.dom4j.Node.hasContent.

hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.

Returns:boolean

true if this Node is a Branch with a nodeCount() of one or more.

isReadOnlyback to summary
public boolean isReadOnly()

Implements org.dom4j.Node.isReadOnly.

Doc from org.dom4j.Node.isReadOnly.

isReadOnly returns true if this node is read only and cannot be modified. Any attempt to modify a read-only Node will result in an UnsupportedOperationException being thrown.

Returns:boolean

true if this Node is read only and cannot be modified otherwise false.

matchesback to summary
public boolean matches(String patternText)

Implements org.dom4j.Node.matches.

Doc from org.dom4j.Node.matches.

matches returns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.

This method does not behave like the <xsl:if> element - if you want that behaviour, to evaluate if an XPath expression matches something, then you can use the following code to be equivalent...

if ( node.selectSingleNode( "/some/path" ) != nulll )
Parameters
patternText:String

is an XPath expression

Returns:boolean

true if this node is returned by the given XPath expression

numberValueOfback to summary
public Number numberValueOf(String xpathExpression)

Implements org.dom4j.Node.numberValueOf.

Doc from org.dom4j.Node.numberValueOf.

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

Returns:Number

the numeric result of the XPath expression or null if the result is not a number.

selectNodesback to summary
public List<Node> selectNodes(String xpathExpression)

Implements org.dom4j.Node.selectNodes.

Doc from org.dom4j.Node.selectNodes.

selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

Returns:List<Node>

the list of Node or String instances depending on the XPath expression

selectNodesback to summary
public List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression)

Implements org.dom4j.Node.selectNodes.

Doc from org.dom4j.Node.selectNodes.

selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

comparisonXPathExpression:String

is the XPath expression used to compare the results by for sorting

Returns:List<Node>

the list of Node instances sorted by the comparisonXPathExpression

selectNodesback to summary
public List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression, boolean removeDuplicates)

Implements org.dom4j.Node.selectNodes.

Doc from org.dom4j.Node.selectNodes.

selectNodes evaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sorted List of Node instances.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

comparisonXPathExpression:String

is the XPath expression used to compare the results by for sorting

removeDuplicates:boolean

if this parameter is true then duplicate values (using the comparisonXPathExpression) are removed from the result List.

Returns:List<Node>

the list of Node instances sorted by the comparisonXPathExpression

selectObjectback to summary
public Object selectObject(String xpathExpression)

Implements org.dom4j.Node.selectObject.

Doc from org.dom4j.Node.selectObject.

selectObject evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of one or more Nodeinstances or a scalar object like a Stringor a Numberinstance depending on the XPath expression.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

Returns:Object

the value of the XPath expression as a Listof Node instances, a Stringor a Numberinstance depending on the XPath expression.

selectSingleNodeback to summary
public Node selectSingleNode(String xpathExpression)

Implements org.dom4j.Node.selectSingleNode.

Doc from org.dom4j.Node.selectSingleNode.

selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.

Parameters
xpathExpression:String

is the XPath expression to be evaluated

Returns:Node

the Node matching the XPath expression

setDocumentback to summary
public void setDocument(Document document)

Implements org.dom4j.Node.setDocument.

Doc from org.dom4j.Node.setDocument.

setDocument sets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.

This method should only be called from inside a Document implementation method and is not intended for general use.

Parameters
document:Document

is the new document of this node.

setNameback to summary
public void setName(String name)

Implements org.dom4j.Node.setName.

Doc from org.dom4j.Node.setName.

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

Parameters
name:String

is the new name of this node

setParentback to summary
public void setParent(Element parent)

Implements org.dom4j.Node.setParent.

Doc from org.dom4j.Node.setParent.

setParent sets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.

This method should only be called from inside an Element implementation method and is not intended for general use.

Parameters
parent:Element

is the new parent of this node.

setTextback to summary
public void setText(String text)

Implements org.dom4j.Node.setText.

Doc from org.dom4j.Node.setText.

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

Parameters
text:String

is the new textual value of this node

supportsParentback to summary
public boolean supportsParent()

Implements org.dom4j.Node.supportsParent.

Doc from org.dom4j.Node.supportsParent.

supportsParent returns true if this node supports the parent relationship.

Some XML tree implementations are singly linked and only support downward navigation through children relationships. The default case is that both parent and children relationships are supported though for memory and performance reasons the parent relationship may not be supported.

Returns:boolean

true if this node supports the parent relationship or false it is not supported

valueOfback to summary
public String valueOf(String xpathExpression)

Implements org.dom4j.Node.valueOf.

Doc from org.dom4j.Node.valueOf.

valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node. The string-value for a given node type is defined in the XPath specification .

Parameters
xpathExpression:String

is the XPath expression to be evaluated

Returns:String

the string-value representation of the results of the XPath expression

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

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
writer:Writer

is the Writer to output the XML to

Exceptions
IOException:
DOCUMENT ME!