org.dom4j
public interface Node extends Cloneable
Node
defines the polymorphic behavior for all XML nodes in a
dom4j tree.
A node can be output as its XML format, can be detached from its position in a document and can have XPath expressions evaluated on itself.
A node may optionally support the parent relationship and may be read only.
Version: $Revision: 1.31 $
Field Summary | |
---|---|
short | ANY_NODE Matches Element nodes |
short | ATTRIBUTE_NODE Matches elements nodes |
short | CDATA_SECTION_NODE Matches elements nodes |
short | COMMENT_NODE Matches Comments nodes |
short | DOCUMENT_NODE Matches Document nodes |
short | DOCUMENT_TYPE_NODE Matches DocumentType nodes |
short | ELEMENT_NODE Matches Element nodes |
short | ENTITY_REFERENCE_NODE Matches elements nodes |
short | MAX_NODE_TYPE The maximum number of node types for sizing purposes |
short | NAMESPACE_NODE Matchs a Namespace Node - NOTE this differs from DOM |
short | PROCESSING_INSTRUCTION_NODE Matches ProcessingInstruction |
short | TEXT_NODE Matches elements nodes |
short | UNKNOWN_NODE Does not match any valid node |
Method Summary | |
---|---|
void | accept(Visitor visitor)
|
String | asXML()
|
Node | asXPathResult(Element parent)
|
Object | clone()
|
XPath | createXPath(String xpathExpression)
|
Node | detach() Removes this node from its parent if there is one. |
Document | getDocument()
|
String | getName()
|
short | getNodeType()
Returns the code according to the type of node. |
String | getNodeTypeName()
DOCUMENT ME!
|
Element | getParent()
|
String | getPath() Returns the XPath expression which will return a node set containing the given node such as /a/b/@c. |
String | getPath(Element context)
Returns the relative XPath expression which will return a node set
containing the given node such as a/b/@c. |
String | getStringValue()
Returns the XPath string-value of this node. |
String | getText() Returns the text of this node. |
String | getUniquePath() Returns the XPath expression which will return a nodeset of one node which is the current node. |
String | getUniquePath(Element context) Returns the relative unique XPath expression from the given context which will return a nodeset of one node which is the current node. |
boolean | hasContent()
|
boolean | isReadOnly()
|
boolean | matches(String xpathExpression)
|
Number | numberValueOf(String xpathExpression)
|
List | selectNodes(String xpathExpression)
|
List | selectNodes(String xpathExpression, String comparisonXPathExpression)
|
List | selectNodes(String xpathExpression, String comparisonXPathExpression, boolean removeDuplicates)
|
Object | selectObject(String xpathExpression)
|
Node | selectSingleNode(String xpathExpression)
|
void | setDocument(Document document)
|
void | setName(String name)
Sets the text data of this node or this method will throw an
|
void | setParent(Element parent)
|
void | setText(String text)
Sets the text data of this node or this method will throw an
|
boolean | supportsParent()
|
String | valueOf(String xpathExpression)
|
void | write(Writer writer)
|
accept
is the method used in the Visitor Pattern.
Parameters: visitor is the visitor in the Visitor Pattern
asXML
returns the textual XML representation of this node.
Returns: the XML representation of this node
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 DOCUMENT ME!
Returns: a Node
which supports the parent relationship
clone
will return a deep clone or if this node is
read-only then clone will return the same instance.
Returns: a deep clone of myself or myself if I am read only.
createXPath
creates an XPath object for the given
xpathExpression. The XPath object allows the variable context to be
specified.
Parameters: xpathExpression is the XPath expression to be evaluated
Returns: an XPath object represeting the given expression
Throws: InvalidXPathException if the XPath expression is invalid
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: the node that has been removed from its parent node if any and its document if any.
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: the document of this node or null if this feature is not
supported or the node is not associated with a
Document
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: the XML name of this node
Returns: a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
Returns: the name of the type of node such as "Document", "Element", "Attribute" or "Text"
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: the parent of this node or null if it is the root of the tree or the parent relationship is not supported.
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: the XPath expression which will return a nodeset containing at least this node.
Parameters: context 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: the XPath expression relative to the given context which will return a nodeset containing at least this node.
Returns: the text from all the child Text and Element nodes appended together.
Returns the text of this node.
Returns: the text for this node.
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: the XPath expression which will return a nodeset containing just this node.
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 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: the XPath expression relative to the given context which will return a nodeset containing just this node.
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: true if this Node
is a Branch with a nodeCount()
of one or more.
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: true if this Node
is read only and cannot be
modified otherwise false.
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: xpathExpression is an XPath expression
Returns: true if this node is returned by the given XPath expression
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 is the XPath expression to be evaluated
Returns: the numeric result of the XPath expression or null if the result is not a number.
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 is the XPath expression to be evaluated
Returns: the list of Node
or String
instances depending on the XPath expression
selectNodes
evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List
of Node
instances.
Parameters: xpathExpression is the XPath expression to be evaluated comparisonXPathExpression is the XPath expression used to compare the results by for sorting
Returns: the list of Node
instances sorted by the
comparisonXPathExpression
selectNodes
evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List
of Node
instances.
Parameters: xpathExpression is the XPath expression to be evaluated comparisonXPathExpression is the XPath expression used to compare the results by for sorting removeDuplicates if this parameter is true then duplicate values (using the comparisonXPathExpression) are removed from the result List.
Returns: the list of Node
instances sorted by the
comparisonXPathExpression
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 is the XPath expression to be evaluated
Returns: the value of the XPath expression as a Listof Node instances, a Stringor a Numberinstance depending on the XPath expression.
selectSingleNode
evaluates an XPath expression and returns
the result as a single Node
instance.
Parameters: xpathExpression is the XPath expression to be evaluated
Returns: the Node
matching the XPath expression
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 is the new document of this node.
Sets the text data of this node or this method will throw an
UnsupportedOperationException
if it is read-only.
Parameters: name is the new name of this node
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 is the new parent of this node.
Sets the text data of this node or this method will throw an
UnsupportedOperationException
if it is read-only.
Parameters: text is the new textual value of this node
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: true if this node supports the parent relationship or false it is not supported
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 is the XPath expression to be evaluated
Returns: the string-value representation of the results of the XPath expression
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 XMLWriter or its derivations.
Parameters: writer
is the Writer
to output the XML to
Throws: IOException DOCUMENT ME!