Interface Node
- 
- All Superinterfaces:
 Cloneable
- All Known Subinterfaces:
 Attribute,Branch,CDATA,CharacterData,Comment,Document,DocumentType,Element,Entity,ProcessingInstruction,Text
- All Known Implementing Classes:
 AbstractAttribute,AbstractBranch,AbstractCDATA,AbstractCharacterData,AbstractComment,AbstractDocument,AbstractDocumentType,AbstractElement,AbstractEntity,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 Cloneable
Nodedefines 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.- See Also:
 supportsParent(),isReadOnly()
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static shortANY_NODEMatches Element nodesstatic shortATTRIBUTE_NODEMatches elements nodesstatic shortCDATA_SECTION_NODEMatches elements nodesstatic shortCOMMENT_NODEMatches Comments nodesstatic shortDOCUMENT_NODEMatches Document nodesstatic shortDOCUMENT_TYPE_NODEMatches DocumentType nodesstatic shortELEMENT_NODEMatches Element nodesstatic shortENTITY_REFERENCE_NODEMatches elements nodesstatic shortMAX_NODE_TYPEThe maximum number of node types for sizing purposesstatic shortNAMESPACE_NODEMatchs a Namespace Node - NOTE this differs from DOMstatic shortPROCESSING_INSTRUCTION_NODEMatches ProcessingInstructionstatic shortTEXT_NODEMatches elements nodesstatic shortUNKNOWN_NODEDoes not match any valid node 
- 
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaccept(Visitor visitor)acceptis the method used in the Visitor Pattern.StringasXML()asXMLreturns the textual XML representation of this node.NodeasXPathResult(Element parent)asXPathResultreturns a version of this node which is capable of being an XPath result.Objectclone()clonewill return a deep clone or if this node is read-only then clone will return the same instance.XPathcreateXPath(String xpathExpression)createXPathcreates an XPath object for the given xpathExpression.Nodedetach()Removes this node from its parent if there is one.DocumentgetDocument()getDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.StringgetName()getNamereturns the name of this node.shortgetNodeType()Returns the code according to the type of node.StringgetNodeTypeName()DOCUMENT ME!ElementgetParent()getParentreturns the parentElementif this node supports the parent relationship or null if it is the root element or does not support the parent relationship.StringgetPath()Returns the XPath expression which will return a node set containing the given node such as /a/b/@c.StringgetPath(Element context)Returns the relative XPath expression which will return a node set containing the given node such as a/b/@c.StringgetStringValue()Returns the XPath string-value of this node.StringgetText()Returns the text of this node.StringgetUniquePath()Returns the XPath expression which will return a nodeset of one node which is the current node.StringgetUniquePath(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.booleanhasContent()hasContentreturns 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.booleanisReadOnly()isReadOnlyreturns true if this node is read only and cannot be modified.booleanmatches(String xpathExpression)matchesreturns true if evaluating the given XPath expression on this node returns a non-empty node set containing this node.NumbernumberValueOf(String xpathExpression)numberValueOfevaluates 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.List<Node>selectNodes(String xpathExpression)selectNodesevaluates an XPath expression and returns the result as aListofNodeinstances orStringinstances depending on the XPath expression.List<Node>selectNodes(String xpathExpression, String comparisonXPathExpression)selectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.List<Node>selectNodes(String xpathExpression, String comparisonXPathExpression, boolean removeDuplicates)selectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.ObjectselectObject(String xpathExpression)selectObjectevaluates an XPath expression and returns the result as anObject.NodeselectSingleNode(String xpathExpression)selectSingleNodeevaluates an XPath expression and returns the result as a singleNodeinstance.voidsetDocument(Document document)setDocumentsets the document of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.voidsetName(String name)Sets the text data of this node or this method will throw anUnsupportedOperationExceptionif it is read-only.voidsetParent(Element parent)setParentsets the parent relationship of this node if the parent relationship is supported or does nothing if the parent relationship is not supported.voidsetText(String text)Sets the text data of this node or this method will throw anUnsupportedOperationExceptionif it is read-only.booleansupportsParent()supportsParentreturns true if this node supports the parent relationship.StringvalueOf(String xpathExpression)valueOfevaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.voidwrite(Writer writer)writewrites this node as the default XML notation for this node. 
 - 
 
- 
- 
Field Detail
- 
ANY_NODE
static final short ANY_NODE
Matches Element nodes- See Also:
 - Constant Field Values
 
 
- 
ELEMENT_NODE
static final short ELEMENT_NODE
Matches Element nodes- See Also:
 - Constant Field Values
 
 
- 
ATTRIBUTE_NODE
static final short ATTRIBUTE_NODE
Matches elements nodes- See Also:
 - Constant Field Values
 
 
- 
TEXT_NODE
static final short TEXT_NODE
Matches elements nodes- See Also:
 - Constant Field Values
 
 
- 
CDATA_SECTION_NODE
static final short CDATA_SECTION_NODE
Matches elements nodes- See Also:
 - Constant Field Values
 
 
- 
ENTITY_REFERENCE_NODE
static final short ENTITY_REFERENCE_NODE
Matches elements nodes- See Also:
 - Constant Field Values
 
 
- 
PROCESSING_INSTRUCTION_NODE
static final short PROCESSING_INSTRUCTION_NODE
Matches ProcessingInstruction- See Also:
 - Constant Field Values
 
 
- 
COMMENT_NODE
static final short COMMENT_NODE
Matches Comments nodes- See Also:
 - Constant Field Values
 
 
- 
DOCUMENT_NODE
static final short DOCUMENT_NODE
Matches Document nodes- See Also:
 - Constant Field Values
 
 
- 
DOCUMENT_TYPE_NODE
static final short DOCUMENT_TYPE_NODE
Matches DocumentType nodes- See Also:
 - Constant Field Values
 
 
- 
NAMESPACE_NODE
static final short NAMESPACE_NODE
Matchs a Namespace Node - NOTE this differs from DOM- See Also:
 - Constant Field Values
 
 
- 
UNKNOWN_NODE
static final short UNKNOWN_NODE
Does not match any valid node- See Also:
 - Constant Field Values
 
 
- 
MAX_NODE_TYPE
static final short MAX_NODE_TYPE
The maximum number of node types for sizing purposes- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Method Detail
- 
supportsParent
boolean supportsParent()
supportsParentreturns 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
 
 
- 
getParent
Element getParent()
getParentreturns the parentElementif 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
Nodeimplementations.- Returns:
 - the parent of this node or null if it is the root of the tree or the parent relationship is not supported.
 
 
- 
setParent
void setParent(Element parent)
setParentsets 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
Elementimplementation method and is not intended for general use.- Parameters:
 parent- is the new parent of this node.
 
- 
getDocument
Document getDocument()
getDocumentreturns theDocumentthat thisNodeis part of if this node supports the parent relationship.This method is an optional feature and may not be supported for all
Nodeimplementations.- Returns:
 - the document of this node or null if this feature is not
         supported or the node is not associated with a
         
Document 
 
- 
setDocument
void setDocument(Document document)
setDocumentsets 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
Documentimplementation method and is not intended for general use.- Parameters:
 document- is the new document of this node.
 
- 
isReadOnly
boolean isReadOnly()
isReadOnlyreturns true if this node is read only and cannot be modified. Any attempt to modify a read-onlyNodewill result in anUnsupportedOperationExceptionbeing thrown.- Returns:
 - true if this 
Nodeis read only and cannot be modified otherwise false. 
 
- 
hasContent
boolean hasContent()
hasContentreturns 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 
Nodeis a Branch with a nodeCount() of one or more. 
 
- 
getName
String getName()
getNamereturns 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
 
 
- 
setName
void setName(String name)
Sets the text data of this node or this method will throw an
UnsupportedOperationExceptionif it is read-only.- Parameters:
 name- is the new name of this node
 
- 
getText
String getText()
Returns the text of this node.
- Returns:
 - the text for this node.
 
 
- 
setText
void setText(String text)
Sets the text data of this node or this method will throw an
UnsupportedOperationExceptionif it is read-only.- Parameters:
 text- is the new textual value of this node
 
- 
getStringValue
String getStringValue()
Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .- Returns:
 - the text from all the child Text and Element nodes appended together.
 
 
- 
getPath
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.
- Returns:
 - the XPath expression which will return a nodeset containing at least this node.
 
 
- 
getPath
String getPath(Element context)
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- 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.
 
 
- 
getUniquePath
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.
- Returns:
 - the XPath expression which will return a nodeset containing just this node.
 
 
- 
getUniquePath
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.
- 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.
 
 
- 
asXML
String asXML()
asXMLreturns the textual XML representation of this node.- Returns:
 - the XML representation of this node
 
 
- 
write
void write(Writer writer) throws IOException
writewrites 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 useXMLWriteror its derivations.- Parameters:
 writer- is theWriterto output the XML to- Throws:
 IOException- DOCUMENT ME!
 
- 
getNodeType
short 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:
 - a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
 
 
- 
getNodeTypeName
String getNodeTypeName()
DOCUMENT ME!- Returns:
 - the name of the type of node such as "Document", "Element", "Attribute" or "Text"
 
 
- 
detach
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:
 - the node that has been removed from its parent node if any and its document if any.
 
 
- 
selectNodes
List<Node> selectNodes(String xpathExpression)
selectNodesevaluates an XPath expression and returns the result as aListofNodeinstances orStringinstances depending on the XPath expression.- Parameters:
 xpathExpression- is the XPath expression to be evaluated- Returns:
 - the list of 
NodeorStringinstances depending on the XPath expression 
 
- 
selectNodes
List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression)
selectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.- Parameters:
 xpathExpression- is the XPath expression to be evaluatedcomparisonXPathExpression- is the XPath expression used to compare the results by for sorting- Returns:
 - the list of 
Nodeinstances sorted by the comparisonXPathExpression 
 
- 
selectNodes
List<Node> selectNodes(String xpathExpression, String comparisonXPathExpression, boolean removeDuplicates)
selectNodesevaluates an XPath expression then sorts the results using a secondary XPath expression Returns a sortedListofNodeinstances.- Parameters:
 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.- Returns:
 - the list of 
Nodeinstances sorted by the comparisonXPathExpression 
 
- 
selectSingleNode
Node selectSingleNode(String xpathExpression)
selectSingleNodeevaluates an XPath expression and returns the result as a singleNodeinstance.- Parameters:
 xpathExpression- is the XPath expression to be evaluated- Returns:
 - the 
Nodematching the XPath expression 
 
- 
valueOf
String valueOf(String xpathExpression)
valueOfevaluates 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
 
 
- 
numberValueOf
Number numberValueOf(String xpathExpression)
numberValueOfevaluates 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.
 
 
- 
matches
boolean matches(String xpathExpression)
matchesreturns 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
 
 
- 
createXPath
XPath createXPath(String xpathExpression) throws InvalidXPathException
createXPathcreates 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
 
- 
asXPathResult
Node asXPathResult(Element parent)
asXPathResultreturns 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 
Nodewhich supports the parent relationship 
 
- 
accept
void accept(Visitor visitor)
acceptis the method used in the Visitor Pattern.- Parameters:
 visitor- is the visitor in the Visitor Pattern
 
- 
clone
Object clone()
clonewill 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.
 
 
 - 
 
 -