org.txml
Class XMLNode

java.lang.Object
  |
  +--org.txml.XMLNode

public class XMLNode
extends java.lang.Object

This class represents one XML node. XML node must have a name (this is the tag name), optionally can have a value (that is a text between opening tag and closing tag), and/or content (which is a list of children nodes).

To create a node that represents the following XML document:

    <animal>Zebra</animal>
 
do the following:
 XMLNode node = new XMLNode("animal", "Zebra");
 


Constructor Summary
XMLNode(java.lang.String nm)
          Creates a node without a value or content.
XMLNode(java.lang.String nm, java.lang.String val)
          Creates a node with value, but no content.
XMLNode(java.lang.String nm, XMLNode child)
          Create a node containig a child node.
 
Method Summary
 void addNode(XMLNode node)
          adds a child node.
 XMLNode deleteNode(int index)
          deletes a child node (by index)
 XMLNode deleteNode(XMLNode child)
          deletes a child node
 java.lang.String getName()
          returns node name (aka tag name)
 XMLNode getNode(int index)
          returns specified content (aka child) node.
 int getNodeCount()
          returns number of content (aka children) nodes.
 java.lang.String getValue()
          returns node value.
 XMLNode select(java.lang.String what)
          selects nodes from the XML tree that starts at this node.
 void setValue(java.lang.String v)
          sets node value to the given string.
 java.lang.String toString()
          Prints content of the current XML node (and all its descendants) into string.
 java.lang.String toString(java.lang.String prefix)
          Prints content of the current node as a formatted XML document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLNode

public XMLNode(java.lang.String nm)
Creates a node without a value or content.

XMLNode

public XMLNode(java.lang.String nm,
               java.lang.String val)
Creates a node with value, but no content.

XMLNode

public XMLNode(java.lang.String nm,
               XMLNode child)
Create a node containig a child node.
Method Detail

getName

public java.lang.String getName()
returns node name (aka tag name)

getValue

public java.lang.String getValue()
returns node value. If node does not have a value returns null.

setValue

public void setValue(java.lang.String v)
sets node value to the given string. If node already has a value, teh new one will be constructed as blank-separated concatenation of the old one, and passed string.

addNode

public void addNode(XMLNode node)
adds a child node.

deleteNode

public XMLNode deleteNode(int index)
deletes a child node (by index)

deleteNode

public XMLNode deleteNode(XMLNode child)
deletes a child node

getNodeCount

public int getNodeCount()
returns number of content (aka children) nodes.

getNode

public XMLNode getNode(int index)
returns specified content (aka child) node. This method will return null if index is out of range.

select

public XMLNode select(java.lang.String what)
selects nodes from the XML tree that starts at this node. If selection result is empty, returns null. Otherwise, returns selected nodes as a content of "select" node (a generated root-level node with the name "select").

toString

public java.lang.String toString()
Prints content of the current XML node (and all its descendants) into string. No formatting is done.
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String prefix)
Prints content of the current node as a formatted XML document. Every line of output is prefixed with prefix. Normally you will just call toString("") to get a nicely formatted document. If prefix is null, does the unformatted output.