IMSEVimse 1.0
Draft

se.kth.cid.xml
Class XmlElement

java.lang.Object
  |
  +--se.kth.cid.xml.XmlElement

public class XmlElement
extends Object

This class represents a node in a very simplified DOM tree. The documents this class represents are subject to a number of constraints: 1. An element cannot have mixed CDATA and sub-elements. All CDATA will be concatenated. 2. The order of elements is preserved amongst elements with the same name. However, no order is preserved between elements of different names.

Version:
$Revision: 1.1.1.1 $
Author:
Mikael Nilsson

Constructor Summary
XmlElement(String nname)
          Constructs an XmlElement with the given name.
XmlElement(String nname, String[] subElements)
          Constructs an XmlElement with the given name and known sub-element names.
 
Method Summary
 void addCDATA(String ncdata)
          Adds CDATA to this element.
 void addSubElement(XmlElement el)
          Adds a sub-element to this element.
 String getAttribute(String attr)
          Returns the value of the attribute with the given name.
 String[] getAttributes()
          Returns the attribute names of this element.
 String getCDATA()
          Returns the CDATA of this element.
 String getName()
          Returns the name of this element.
 XmlElement getParent()
          Returns the parent of this element.
 String[] getSubElementNames()
          Returns the names of all sub-elements.
 int getSubElementNumber()
           
 XmlElement[] getSubElements(String elname)
          Returns all sub-elements with the given name.
 void removeSubElement(XmlElement el)
          Removes the specified sub-element from this element.
 void setAttribute(String attribute, String value)
          Sets the given attribute to the given value.
 void setCDATA(String ncdata)
          Sets the CDATA of this element.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XmlElement

public XmlElement(String nname)
Constructs an XmlElement with the given name.
Parameters:
nname - the name of this XmlElement.

XmlElement

public XmlElement(String nname,
                  String[] subElements)
Constructs an XmlElement with the given name and known sub-element names. This constructor is very useful when you know in advance which sub-element names will exist in this element, but want to be sure in which order they are presented.
Parameters:
nname - the name of this XmlElement.
subElements - the names of the allowed sub-elements.
Method Detail

getParent

public XmlElement getParent()
Returns the parent of this element.
Returns:
the parent of this element. May be null.

getName

public String getName()
Returns the name of this element.
Returns:
the name of this element.

getCDATA

public String getCDATA()
Returns the CDATA of this element.
Returns:
the CDATA of this element. May be null.

setCDATA

public void setCDATA(String ncdata)
Sets the CDATA of this element.
Parameters:
ncdata - the CDATA of this element.
Throws:
HasSubElementsException - if this element already has sub-elements.

addCDATA

public void addCDATA(String ncdata)
Adds CDATA to this element.
Parameters:
ncdata - the additional CDATA of this element.

getSubElementNames

public String[] getSubElementNames()
Returns the names of all sub-elements. If the names were specified in the constructor, they are returned in that order. Otherwise, they are returned in the order they have been added.
Returns:
the names of all sub-elements. Never null, but may be empty.

getSubElementNumber

public int getSubElementNumber()

getSubElements

public XmlElement[] getSubElements(String elname)
Returns all sub-elements with the given name.
Parameters:
elname - the name of the elements wanted.
Returns:
all sub-elements with the given name. Never null, but may be empty.

addSubElement

public void addSubElement(XmlElement el)
                   throws UnknownElementNameException
Adds a sub-element to this element. This is not allowed if the known sub-elements were specified in the constructor and this sub-element is not among them.
Parameters:
el - the element to add.

removeSubElement

public void removeSubElement(XmlElement el)
Removes the specified sub-element from this element.
Parameters:
el - the sub-element to remove.

getAttributes

public String[] getAttributes()
Returns the attribute names of this element.
Returns:
the attribute names of this element.

getAttribute

public String getAttribute(String attr)
Returns the value of the attribute with the given name.
Parameters:
attr - the attribute of interest.
Returns:
the value of the attribute with the given name.

setAttribute

public void setAttribute(String attribute,
                         String value)
Sets the given attribute to the given value. If value is null, the attribute is removed.
Parameters:
attribute - the attribute to modify.
value - the value of the attribute, or null if the attribute should be removed.

toString

public String toString()
Overrides:
toString in class Object

IMSEVimse 1.0
Draft

Centre for user-oriented IT -design