org.kxml.kdom
Class Node

java.lang.Object
  extended by org.kxml.kdom.Node
All Implemented Interfaces:
XmlIO
Direct Known Subclasses:
Document, Element

public class Node
extends java.lang.Object
implements XmlIO

A common base class for Document and Element, also used for storing XML fragments.


Field Summary
protected  java.util.Vector children
           
protected  java.lang.StringBuffer types
           
 
Constructor Summary
Node()
           
 
Method Summary
 void addChild(int index, int type, java.lang.Object child)
          inserts the given child object of the given type at the given index.
 void addChild(int type, java.lang.Object child)
          convenience method for addChild (getChildCount (), child)
 Element createElement(java.lang.String namespace, java.lang.String name)
          Builds a default element with the given properties.
 java.lang.Object getChild(int index)
          Returns the child object at the given index.
 int getChildCount()
          Returns the number of child objects
 Element getElement(int index)
          returns the element at the given index.
 Element getElement(java.lang.String name)
          Convenience method for getElement (getNamespace (), name).
 Element getElement(java.lang.String namespace, java.lang.String name)
          Returns the element with the given namespace and name.
 java.lang.String getName()
          returns "#document-fragment".
 java.lang.String getNamespace()
          Returns the namespace of the current element.
 java.lang.String getText()
          returns the text content if the element has text-only content.
 java.lang.String getText(int index)
          Returns the text node with the given index or null if the node with the given index is not a text node.
 int getType(int index)
          Returns the type of the child at the given index.
 int indexOf(java.lang.String name, int startIndex)
          Convenience method for indexOf (getNamespace (), name, startIndex).
 int indexOf(java.lang.String namespace, java.lang.String name, int startIndex)
          Performs search for an element with the given namespace and name, starting at the given start index.
 void parse(AbstractXmlParser parser)
          Recursively builds the child elements from the given parser until an end tag or end document is found.
 void removeChild(int idx)
          Removes the child object at the given index
 java.lang.String toString()
          returns a valid XML representation of this Element including attributes and children.
 void write(AbstractXmlWriter writer)
          Writes this node to the given XmlWriter.
 void writeChildren(AbstractXmlWriter writer)
          Writes the children of this node to the given XmlWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

children

protected java.util.Vector children

types

protected java.lang.StringBuffer types
Constructor Detail

Node

public Node()
Method Detail

addChild

public void addChild(int index,
                     int type,
                     java.lang.Object child)
inserts the given child object of the given type at the given index.


addChild

public void addChild(int type,
                     java.lang.Object child)
convenience method for addChild (getChildCount (), child)


createElement

public Element createElement(java.lang.String namespace,
                             java.lang.String name)
Builds a default element with the given properties. Elements should always be created using this method instead of the constructor in order to enable construction of specialized subclasses by deriving custom Document classes. Please note: For no namespace, please use Xml.NO_NAMESPACE, null is not a legal value. Currently, null is converted to Xml.NO_NAMESPACE, but future versions may throw an exception.


getChild

public java.lang.Object getChild(int index)
Returns the child object at the given index. For child elements, an Element object is returned. For all other child types, a String is returned.


getChildCount

public int getChildCount()
Returns the number of child objects


getElement

public Element getElement(int index)
returns the element at the given index. If the node at the given index is a text node, null is returned


getElement

public Element getElement(java.lang.String name)
Convenience method for getElement (getNamespace (), name).


getElement

public Element getElement(java.lang.String namespace,
                          java.lang.String name)
Returns the element with the given namespace and name. If the element is not found, or more than one matching elements are found, an exception is thrown.


getName

public java.lang.String getName()
returns "#document-fragment". For elements, the element name is returned


getNamespace

public java.lang.String getNamespace()
Returns the namespace of the current element. For Node and Document, Xml.NO_NAMESPACE is returned.


getText

public java.lang.String getText()
returns the text content if the element has text-only content. Throws an exception for mixed content


getText

public java.lang.String getText(int index)
Returns the text node with the given index or null if the node with the given index is not a text node.


getType

public int getType(int index)
Returns the type of the child at the given index. Possible types are ELEMENT, TEXT, COMMENT, and PROCESSING_INSTRUCTION


indexOf

public int indexOf(java.lang.String name,
                   int startIndex)
Convenience method for indexOf (getNamespace (), name, startIndex).


indexOf

public int indexOf(java.lang.String namespace,
                   java.lang.String name,
                   int startIndex)
Performs search for an element with the given namespace and name, starting at the given start index. A null namespace matches any namespace, please use Xml.NO_NAMESPACE for no namespace). returns -1 if no matching element was found.


parse

public void parse(AbstractXmlParser parser)
           throws java.io.IOException
Recursively builds the child elements from the given parser until an end tag or end document is found. The end tag is not consumed.

Specified by:
parse in interface XmlIO
Throws:
java.io.IOException

removeChild

public void removeChild(int idx)
Removes the child object at the given index


toString

public java.lang.String toString()
returns a valid XML representation of this Element including attributes and children.

Overrides:
toString in class java.lang.Object

write

public void write(AbstractXmlWriter writer)
           throws java.io.IOException
Writes this node to the given XmlWriter. For node and document, this method is identical to writeChildren, except that the stream is flushed automatically.

Specified by:
write in interface XmlIO
Throws:
java.io.IOException

writeChildren

public void writeChildren(AbstractXmlWriter writer)
                   throws java.io.IOException
Writes the children of this node to the given XmlWriter.

Throws:
java.io.IOException