erland.util
Class XMLNode

java.lang.Object
  extended by erland.util.XMLNode

public class XMLNode
extends Object

A node object for an XML document tree. An object of this class represents a node and all its child nodes

Author:
Erland Isaksson

Constructor Summary
XMLNode(String name, Map attributes)
          Creates a new empty XML node
 
Method Summary
 void addChild(XMLNode node)
          Add a child node
 void delChild(String name)
          Delete the first child node matching the name If the child node has child nodes itself these will also be deleted.
 void delChild(XMLNode node)
          Delete a child node.
 void delChilds()
          Delete all child nodes.
 Iterator getAttributes()
          Get an iterator with the name of all attributes for the node
 String getAttributeValue(String attribute)
          Get the value of a specified attribute for the node
 Iterator getChilds()
          Get all child nodes
 String getName()
          Get the name of this node
 String getValue()
          Get the value of this node
 void insertChild(XMLNode node)
          Insert a child node
 void replaceChild(XMLNode currentNode, XMLNode newNode)
          Replaces an existing child node with a new one
 void setAttributeValue(String name, String value)
          Set the value of a specified attribute for the node
 void setName(String name)
          Set the name of this node
 void setValue(String value)
          Set the value of this node
 String toString()
          Get a string representation of the XML node and all its child nodes
 String toString(boolean lineFeeds)
          Get a string representation of the XML node and all its child nodes.
 String toString(boolean lineFeeds, boolean preprocessor)
          Get a string representation of the XML node and all its child nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLNode

public XMLNode(String name,
               Map attributes)
Creates a new empty XML node

Parameters:
name - The name of the node
attributes - The value of the attribute strings for the node, set to null if no attributes exist
Method Detail

setName

public void setName(String name)
Set the name of this node

Parameters:
name - The name of the node

getName

public String getName()
Get the name of this node

Returns:
The name of the node

getValue

public String getValue()
Get the value of this node

Returns:
The value of the node, will be null or and empty string if child nodes exist

setValue

public void setValue(String value)
Set the value of this node

Parameters:
value - The value of the node

getAttributes

public Iterator getAttributes()
Get an iterator with the name of all attributes for the node

Returns:
An Iterator with all attribute names

getAttributeValue

public String getAttributeValue(String attribute)
Get the value of a specified attribute for the node

Parameters:
attribute - The name of the attribute to get
Returns:
The value of the attribute

setAttributeValue

public void setAttributeValue(String name,
                              String value)
Set the value of a specified attribute for the node

Parameters:
name - The name of the attribute to set
value - The value of the attribute

getChilds

public Iterator getChilds()
Get all child nodes

Returns:
An Iterator with all child nodes

addChild

public void addChild(XMLNode node)
Add a child node

Parameters:
node - The child node to add

replaceChild

public void replaceChild(XMLNode currentNode,
                         XMLNode newNode)
Replaces an existing child node with a new one

Parameters:
currentNode - The current child not which should be replaced
newNode - The new child node which is should be replaced with

insertChild

public void insertChild(XMLNode node)
Insert a child node

Parameters:
node - The child node to insert

delChild

public void delChild(XMLNode node)
Delete a child node. If the child node has child nodes itself these will also be deleted.

Parameters:
node - The child node which should be deleted
See Also:
delChild(String)

delChilds

public void delChilds()
Delete all child nodes. If the child nodes has child nodes themself these will also be deleted.

See Also:
delChild(String), delChild(XMLNode)

delChild

public void delChild(String name)
Delete the first child node matching the name If the child node has child nodes itself these will also be deleted.

Parameters:
name - The name of the child node which should be deleted
See Also:
delChild(XMLNode)

toString

public String toString()
Get a string representation of the XML node and all its child nodes

Overrides:
toString in class Object
Returns:
A string representatino of the XML node and its child nodes

toString

public String toString(boolean lineFeeds)
Get a string representation of the XML node and all its child nodes. You have option to select if each node should be separated with a linefeed character or not

Parameters:
lineFeeds - Indicates that each node should be printed on its own line
Returns:
A string representationi of the XML node and its child nodes

toString

public String toString(boolean lineFeeds,
                       boolean preprocessor)
Get a string representation of the XML node and all its child nodes. You have option to select if each node should be separated with a linefeed character or not, and you can also choos if the preprocessor directive should be printed or not

Parameters:
lineFeeds - Indicates that each node should be printed on its own line
preprocessor - Indicates that a preprocessor directive should be printed at the beginning
Returns:
A string representationi of the XML node and its child nodes


Copyright © 2003-2005 Erland Isaksson. All Rights Reserved.