java.lang.Cloneable
Attribute
, Branch
, CDATA
, Comment
, Document
, DocumentType
, Element
, Entity
, CharacterData
, ProcessingInstruction
, Text
AbstractAttribute
, AbstractBranch
, AbstractCDATA
, AbstractComment
, AbstractDocument
, AbstractDocumentType
, AbstractElement
, AbstractEntity
, AbstractCharacterData
, AbstractNode
, AbstractProcessingInstruction
, AbstractText
, BaseElement
, BeanAttribute
, BeanElement
, DatatypeAttribute
, DatatypeElement
, DefaultAttribute
, DefaultCDATA
, DefaultComment
, DefaultDocument
, DefaultDocumentType
, DefaultElement
, DefaultEntity
, DefaultNamespace
, DefaultProcessingInstruction
, DefaultText
, DOMAttribute
, DOMCDATA
, DOMComment
, DOMDocument
, DOMDocumentType
, DOMElement
, DOMEntityReference
, DOMNamespace
, DOMProcessingInstruction
, DOMText
, FlyweightAttribute
, FlyweightCDATA
, FlyweightComment
, FlyweightEntity
, FlyweightProcessingInstruction
, FlyweightText
, IndexedElement
, Namespace
, NonLazyElement
, UserDataAttribute
, UserDataElement
public interface Node
extends java.lang.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.supportsParent()
,
isReadOnly()
Modifier and Type | Field | Description |
---|---|---|
static short |
ANY_NODE |
Matches Element nodes
|
static short |
ATTRIBUTE_NODE |
Matches elements nodes
|
static short |
CDATA_SECTION_NODE |
Matches elements nodes
|
static short |
COMMENT_NODE |
Matches Comments nodes
|
static short |
DOCUMENT_NODE |
Matches Document nodes
|
static short |
DOCUMENT_TYPE_NODE |
Matches DocumentType nodes
|
static short |
ELEMENT_NODE |
Matches Element nodes
|
static short |
ENTITY_REFERENCE_NODE |
Matches elements nodes
|
static short |
MAX_NODE_TYPE |
The maximum number of node types for sizing purposes
|
static short |
NAMESPACE_NODE |
Matchs a Namespace Node - NOTE this differs from DOM
|
static short |
PROCESSING_INSTRUCTION_NODE |
Matches ProcessingInstruction
|
static short |
TEXT_NODE |
Matches elements nodes
|
static short |
UNKNOWN_NODE |
Does not match any valid node
|
Modifier and Type | Method | Description |
---|---|---|
void |
accept(Visitor visitor) |
accept is the method used in the Visitor Pattern. |
java.lang.String |
asXML() |
asXML returns the textual XML representation of this node. |
Node |
asXPathResult(Element parent) |
asXPathResult returns a version of this node which is
capable of being an XPath result. |
java.lang.Object |
clone() |
clone will return a deep clone or if this node is
read-only then clone will return the same instance. |
XPath |
createXPath(java.lang.String xpathExpression) |
createXPath creates an XPath object for the given
xpathExpression. |
Node |
detach() |
Removes this node from its parent if there is one.
|
Document |
getDocument() |
getDocument returns the Document that this
Node is part of if this node supports the parent
relationship. |
java.lang.String |
getName() |
getName returns the name of this node. |
short |
getNodeType() |
Returns the code according to the type of node.
|
java.lang.String |
getNodeTypeName() |
DOCUMENT ME!
|
Element |
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. |
java.lang.String |
getPath() |
Returns the XPath expression which will return a node set containing the
given node such as /a/b/@c.
|
java.lang.String |
getPath(Element context) |
Returns the relative XPath expression which will return a node set
containing the given node such as a/b/@c.
|
java.lang.String |
getStringValue() |
Returns the XPath string-value of this node.
|
java.lang.String |
getText() |
Returns the text of this node.
|
java.lang.String |
getUniquePath() |
Returns the XPath expression which will return a nodeset of one node
which is the current node.
|
java.lang.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() |
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. |
boolean |
isReadOnly() |
isReadOnly returns true if this node is read only and
cannot be modified. |
boolean |
matches(java.lang.String xpathExpression) |
matches returns true if evaluating the given XPath
expression on this node returns a non-empty node set containing this
node. |
java.lang.Number |
numberValueOf(java.lang.String xpathExpression) |
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. |
java.util.List<Node> |
selectNodes(java.lang.String xpathExpression) |
selectNodes evaluates an XPath expression and returns the
result as a List of Node instances or
String instances depending on the XPath expression. |
java.util.List<Node> |
selectNodes(java.lang.String xpathExpression,
java.lang.String comparisonXPathExpression) |
selectNodes evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List of Node instances. |
java.util.List<Node> |
selectNodes(java.lang.String xpathExpression,
java.lang.String comparisonXPathExpression,
boolean removeDuplicates) |
selectNodes evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List of Node instances. |
java.lang.Object |
selectObject(java.lang.String xpathExpression) |
selectObject evaluates an XPath expression and returns the
result as an Object . |
Node |
selectSingleNode(java.lang.String xpathExpression) |
selectSingleNode evaluates an XPath expression and returns
the result as a single Node instance. |
void |
setDocument(Document document) |
setDocument sets the document of this node if the parent
relationship is supported or does nothing if the parent relationship is
not supported. |
void |
setName(java.lang.String name) |
Sets the text data of this node or this method will throw an
UnsupportedOperationException if it is read-only. |
void |
setParent(Element parent) |
setParent sets the parent relationship of this node if the
parent relationship is supported or does nothing if the parent
relationship is not supported. |
void |
setText(java.lang.String text) |
Sets the text data of this node or this method will throw an
UnsupportedOperationException if it is read-only. |
boolean |
supportsParent() |
supportsParent returns true if this node supports the
parent relationship. |
java.lang.String |
valueOf(java.lang.String xpathExpression) |
valueOf evaluates an XPath expression and returns the
textual representation of the results the XPath string-value of this
node. |
void |
write(java.io.Writer writer) |
write writes this node as the default XML notation for
this node. |
static final short ANY_NODE
static final short ELEMENT_NODE
static final short ATTRIBUTE_NODE
static final short TEXT_NODE
static final short CDATA_SECTION_NODE
static final short ENTITY_REFERENCE_NODE
static final short PROCESSING_INSTRUCTION_NODE
static final short COMMENT_NODE
static final short DOCUMENT_NODE
static final short DOCUMENT_TYPE_NODE
static final short NAMESPACE_NODE
static final short UNKNOWN_NODE
static final short MAX_NODE_TYPE
boolean 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.
Element 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.
void setParent(Element parent)
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.
parent
- is the new parent of this node.Document 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.
Document
void setDocument(Document document)
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.
document
- is the new document of this node.boolean 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.
Node
is read only and cannot be
modified otherwise false.boolean 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.
Node
is a Branch with a nodeCount()
of one or more.java.lang.String 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.
void setName(java.lang.String name)
Sets the text data of this node or this method will throw an
UnsupportedOperationException
if it is read-only.
name
- is the new name of this nodejava.lang.String getText()
Returns the text of this node.
void setText(java.lang.String text)
Sets the text data of this node or this method will throw an
UnsupportedOperationException
if it is read-only.
text
- is the new textual value of this nodejava.lang.String getStringValue()
java.lang.String 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.
java.lang.String getPath(Element context)
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.java.lang.String 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.
java.lang.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. This method will use the XPath index operator to restrict the path if multiple elements with the same name occur on the path.
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.java.lang.String asXML()
asXML
returns the textual XML representation of this node.
void write(java.io.Writer writer) throws java.io.IOException
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.
writer
- is the Writer
to output the XML tojava.io.IOException
- DOCUMENT ME!short getNodeType()
java.lang.String getNodeTypeName()
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() );
java.util.List<Node> selectNodes(java.lang.String xpathExpression)
selectNodes
evaluates an XPath expression and returns the
result as a List
of Node
instances or
String
instances depending on the XPath expression.
xpathExpression
- is the XPath expression to be evaluatedNode
or String
instances depending on the XPath expressionjava.lang.Object selectObject(java.lang.String xpathExpression)
selectObject
evaluates an XPath expression and returns the
result as an Object
. The object returned can either be a List
of one or more Node
instances or a scalar object like a
String
or a Number
instance depending on the XPath
expression.
xpathExpression
- is the XPath expression to be evaluatedList
of Node
instances, a String
or a Number
instance
depending on the XPath expression.java.util.List<Node> selectNodes(java.lang.String xpathExpression, java.lang.String comparisonXPathExpression)
selectNodes
evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List
of Node
instances.
xpathExpression
- is the XPath expression to be evaluatedcomparisonXPathExpression
- is the XPath expression used to compare the results by for
sortingNode
instances sorted by the
comparisonXPathExpressionjava.util.List<Node> selectNodes(java.lang.String xpathExpression, java.lang.String comparisonXPathExpression, boolean removeDuplicates)
selectNodes
evaluates an XPath expression then sorts the
results using a secondary XPath expression Returns a sorted
List
of Node
instances.
xpathExpression
- is the XPath expression to be evaluatedcomparisonXPathExpression
- is the XPath expression used to compare the results by for
sortingremoveDuplicates
- if this parameter is true then duplicate values (using the
comparisonXPathExpression) are removed from the result List.Node
instances sorted by the
comparisonXPathExpressionNode selectSingleNode(java.lang.String xpathExpression)
selectSingleNode
evaluates an XPath expression and returns
the result as a single Node
instance.
xpathExpression
- is the XPath expression to be evaluatedNode
matching the XPath expressionjava.lang.String valueOf(java.lang.String xpathExpression)
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 .
xpathExpression
- is the XPath expression to be evaluatedjava.lang.Number numberValueOf(java.lang.String xpathExpression)
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.
xpathExpression
- is the XPath expression to be evaluatedboolean matches(java.lang.String xpathExpression)
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 )
xpathExpression
- is an XPath expressionXPath createXPath(java.lang.String xpathExpression) throws InvalidXPathException
createXPath
creates an XPath object for the given
xpathExpression. The XPath object allows the variable context to be
specified.
xpathExpression
- is the XPath expression to be evaluatedInvalidXPathException
- if the XPath expression is invalidNode asXPathResult(Element parent)
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.
parent
- DOCUMENT ME!Node
which supports the parent relationshipvoid accept(Visitor visitor)
accept
is the method used in the Visitor Pattern.
visitor
- is the visitor in the Visitor Patternjava.lang.Object clone()
clone
will return a deep clone or if this node is
read-only then clone will return the same instance.