Save This Page
Home » dom4j-1.6.1 » org.dom4j » [javadoc | source]
org.dom4j
public interface: Node [javadoc | source]

All Implemented Interfaces:
    Cloneable

All Known Implementing Classes:
    DOMAttribute, FlyweightAttribute, AbstractText, FlyweightProcessingInstruction, BaseElement, DOMComment, Document, Entity, DefaultAttribute, AbstractCharacterData, DefaultCDATA, DefaultText, DOMDocument, AbstractComment, Branch, Text, NonLazyElement, AbstractCDATA, AbstractEntity, FlyweightCDATA, DatatypeElement, DOMDocumentType, DOMCDATA, DefaultElement, DefaultDocumentType, DOMNamespace, FlyweightEntity, AbstractDocumentType, UserDataAttribute, Attribute, BeanAttribute, FlyweightText, DOMElement, AbstractProcessingInstruction, CharacterData, FlyweightComment, CDATA, Namespace, AbstractElement, AbstractDocument, UserDataElement, BeanElement, Comment, DocumentType, AbstractNode, ProcessingInstruction, LElement, IndexedElement, DefaultDocument, DatatypeAttribute, DOMEntityReference, DefaultComment, DOMText, DefaultProcessingInstruction, AbstractAttribute, DefaultEntity, DefaultNamespace, AbstractBranch, DOMProcessingInstruction, Element

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.

Field Summary
 short ANY_NODE    Matches Element nodes 
 short ELEMENT_NODE    Matches Element nodes 
 short ATTRIBUTE_NODE    Matches elements nodes 
 short TEXT_NODE    Matches elements nodes 
 short CDATA_SECTION_NODE    Matches elements nodes 
 short ENTITY_REFERENCE_NODE    Matches elements nodes 
 short PROCESSING_INSTRUCTION_NODE    Matches ProcessingInstruction 
 short COMMENT_NODE    Matches Comments nodes 
 short DOCUMENT_NODE    Matches Document nodes 
 short DOCUMENT_TYPE_NODE    Matches DocumentType nodes 
 short NAMESPACE_NODE    Matchs a Namespace Node - NOTE this differs from DOM 
 short UNKNOWN_NODE    Does not match any valid node 
 short MAX_NODE_TYPE    The maximum number of node types for sizing purposes 
Method from org.dom4j.Node Summary:
accept,   asXML,   asXPathResult,   clone,   createXPath,   detach,   getDocument,   getName,   getNodeType,   getNodeTypeName,   getParent,   getPath,   getPath,   getStringValue,   getText,   getUniquePath,   getUniquePath,   hasContent,   isReadOnly,   matches,   numberValueOf,   selectNodes,   selectNodes,   selectNodes,   selectObject,   selectSingleNode,   setDocument,   setName,   setParent,   setText,   supportsParent,   valueOf,   write
Method from org.dom4j.Node Detail:
 public  void accept(Visitor visitor)

    accept is the method used in the Visitor Pattern.

 public String asXML()

    asXML returns the textual XML representation of this node.

 public Node 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.

 public Object clone()

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

 public XPath createXPath(String xpathExpression) throws InvalidXPathException

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

 public 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() );
 public 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.

 public 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.

 public 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.
 public String getNodeTypeName()
    DOCUMENT ME!
 public 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.

 public 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.

 public 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.
 public String getStringValue()
    Returns the XPath string-value of this node. The behaviour of this method is defined in the XPath specification .
 public String getText()

    Returns the text of this node.

 public 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.

 public 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.

 public 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.

 public 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.

 public boolean matches(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 )
 public Number numberValueOf(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.

 public List selectNodes(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.

 public List selectNodes(String xpathExpression,
    String comparisonXPathExpression)

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

 public List selectNodes(String xpathExpression,
    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.

 public Object selectObject(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.

 public Node selectSingleNode(String xpathExpression)

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

 public  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.

 public  void setName(String name)

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

 public  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.

 public  void setText(String text)

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

 public 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.

 public String valueOf(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 .

 public  void write(Writer writer) throws 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 org.dom4j.io.XMLWriter or its derivations.