nu.xom
Class Node

java.lang.Object
  extended bynu.xom.Node
Direct Known Subclasses:
Attribute, LeafNode, ParentNode

public abstract class Node
extends java.lang.Object

This is the generic superclass for all the contents of an XML document. There are exactly seven kinds of nodes in XOM:

Every instance of Node is an instance of one of these seven classes (including, possibly, one of their subclasses).

Version:
1.0d21
Author:
Elliotte Rusty Harold

Method Summary
protected  void checkDetach()
           Subclasses can override this method to perform additional checks beyond what XML 1.0 requires.
abstract  Node copy()
           Returns a deep copy of this node with no parent, that can be added to this document or a different one.
 void detach()
           Removes this node from its parent so that it can be added to a different parent node or document.
 boolean equals(java.lang.Object o)
           Tests for node identity.
 java.lang.String getBaseURI()
           Returns the base URI of this node as specified by XML Base, or null if this is not known.
abstract  Node getChild(int position)
           Returns the indexth child of this node.
abstract  int getChildCount()
           Returns the number of children of this node.
 Document getDocument()
           Returns the document that contains this node, or null if this node is not currently part of a document.
 ParentNode getParent()
           Returns the node that contains this node, or null if this node does not have a parent.
abstract  java.lang.String getValue()
           Returns the XPath 1.0 string-value of this node.
abstract  boolean hasChildren()
           Returns true if this node currently has children.
 int hashCode()
           Returns a unique identifier for this node.
abstract  java.lang.String toString()
           Returns a string representation of this node suitable for debugging and diagnosis.
abstract  java.lang.String toXML()
           Returns the actual XML form of this node, such as might be copied and pasted from the original document.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getValue

public abstract java.lang.String getValue()

Returns the XPath 1.0 string-value of this node.

Returns:
the XPath 1.0 string-value of this node

getDocument

public final Document getDocument()

Returns the document that contains this node, or null if this node is not currently part of a document. Each node belongs to no more than one document at a time. If this node is a Document, then it returns this node.

Returns:
the Document which this node is a part of

getBaseURI

public java.lang.String getBaseURI()

Returns the base URI of this node as specified by XML Base, or null if this is not known. In most cases, this is the URL against which relative URLs in this node should be resolved.

Currently, the value of the base URI is determined as follows:

Absolutization takes place as specified by the XML Base specification. However, it is not always possible to absolutize a relative URI, in which case only the relative URI will be returned.

Returns:
the base URI of this node

getParent

public final ParentNode getParent()

Returns the node that contains this node, or null if this node does not have a parent.

Returns:
the parent Element or Document that contains this node

detach

public final void detach()

Removes this node from its parent so that it can be added to a different parent node or document.

Throws:
XMLException - if subclass constraints prohibit this node from being detached

checkDetach

protected void checkDetach()

Subclasses can override this method to perform additional checks beyond what XML 1.0 requires. For example, an HTMLDocument subclass might not allow the body element to be detached.

Throws:
XMLException - if local constraints in a subclass do not allow this node to be detached

hasChildren

public abstract boolean hasChildren()

Returns true if this node currently has children.

Returns:
true if this node contains child nodes

getChild

public abstract Node getChild(int position)

Returns the indexth child of this node.

Parameters:
position - the index of the child node to return
Returns:
the positionth child node of this node
Throws:
java.lang.IndexOutOfBoundsException - if this node does not have children.

getChildCount

public abstract int getChildCount()

Returns the number of children of this node. This is always non-negative (greater than or equal to zero).

Returns:
the number of children of this node

copy

public abstract Node copy()

Returns a deep copy of this node with no parent, that can be added to this document or a different one.

Per Bloch, the Cloneable interface is just a mess and should be avoided. However, I do not follow his suggestion of a copy constructor exclusively because it is useful to be able to copy a node without knowing its more specific type. Ken Arnold agrees with this. It's more effective for subclasses that can return an instance of the subclass.

Returns:
a copy of this node without a parent and unattached to any document

toXML

public abstract java.lang.String toXML()

Returns the actual XML form of this node, such as might be copied and pasted from the original document.

Returns:
a String containing an XML representation of this node

equals

public final boolean equals(java.lang.Object o)

Tests for node identity. That is, two Node objects are equal if and only if they are the same object.

Parameters:
o - the object compared for equality to this node
Returns:
true if o is this node; false otherwise
See Also:
Object.equals(Object)

hashCode

public final int hashCode()

Returns a unique identifier for this node. The value returned is the same as returned by super.hashCode() because nodes use identity semantics.

Returns:
a probably unique identifier for this node
See Also:
Object.hashCode()

toString

public abstract java.lang.String toString()

Returns a string representation of this node suitable for debugging and diagnosis. This is not the XML representation of this node.

Returns:
a non-XML string representation of this node
See Also:
Object.toString()


Copyright 2002-2004 Elliotte Rusty Harold
elharo@metalab.unc.edu