Package diva.util.xml
Class XmlElement
- java.lang.Object
 - 
- diva.util.xml.XmlElement
 
 
- 
public class XmlElement extends java.lang.ObjectAn XmlElement is a node of a tree representing an XML file. It is a concrete class. An XmlReader object will construct a tree of XmlElements from an XML file and place it into an XmlDocument. Applications can traverse a tree of XmlElements to extract data or build their own application-specific data structure. They can also construct a tree of XmlElements and add it to an XmlDocument and generate an XML output file.- Version:
 - $Id$
 - Author:
 - Steve Neuendorffer, John Reekie
 
 
- 
- 
Constructor Summary
Constructors Constructor Description XmlElement()Create a new XmlElement of unknown type.XmlElement(java.lang.String type)Create a new XmlElement with element type given by the string.XmlElement(java.lang.String type, java.util.Map attrs)Create a new XmlElement with element type with the given name and the given attributes. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddElement(XmlElement e)Add a child element to this element.voidappendPCData(java.lang.String s)Add the String to the end of the current PCDATA for this element.java.util.IteratorattributeNames()Return an enumeration over the names of the attributes in this schematic.booleancontainsElement(XmlElement elt)Test if this element contains the given element.intelementCount()Return the number of child elements.java.util.Iteratorelements()Return an Iterator of all the child elements of this element.java.util.Iteratorelements(java.lang.String type)Return an Iterator of all the child elements of this element that have the given element type.java.lang.StringgetAttribute(java.lang.String name)Return the value of the attribute with the given name, or null if there isn't one.java.util.MapgetAttributeMap()Return the map from attribute names to value.java.util.ListgetChildList()Return the list of child elements.XmlElementgetElement(java.lang.String type)Return the first child element of this element with the given type, or null if there isn't one.XmlElementgetElement(java.lang.String type, java.lang.String name)Return the first child element of this element with the given type and name, or null if there isn't one.XmlElementgetParent()Return the parent element of this element, or null if it has no parent.java.lang.StringgetPCData()Return the PCData that is associated with this XmlElement.java.lang.StringgetType()Return the type of this XmlElement.booleanhasAttribute(java.lang.String name)Test if this element has the attribute with the given name.voidremoveAttribute(java.lang.String name)Remove an attribute from this element.voidremoveElement(XmlElement e)Remove a child element from this element.voidsetAttribute(java.lang.String name, java.lang.String value)Set the attribute with the given name to the given value.voidsetParent(XmlElement p)Set the parent element of this element.voidsetPCData(java.lang.String s)Set the text of this element to the given string.voidsetType(java.lang.String s)Set the type of this element.java.lang.StringtoString()Convert this element to a string in XML.voidwriteXML(java.io.Writer out, java.lang.String prefix)Print this element to a Writer. 
 - 
 
- 
- 
Constructor Detail
- 
XmlElement
public XmlElement(java.lang.String type)
Create a new XmlElement with element type given by the string. The element has no attributes and no child elements.- Parameters:
 type- The element type
 
- 
XmlElement
public XmlElement()
Create a new XmlElement of unknown type. 
- 
XmlElement
public XmlElement(java.lang.String type, java.util.Map attrs)Create a new XmlElement with element type with the given name and the given attributes. The element starts with no child elements.- Parameters:
 type- The element typeattrs- The attributes of this XmlElement.
 
 - 
 
- 
Method Detail
- 
addElement
public void addElement(XmlElement e)
Add a child element to this element. Child elements are ordered. 
- 
appendPCData
public void appendPCData(java.lang.String s)
Add the String to the end of the current PCDATA for this element. 
- 
attributeNames
public java.util.Iterator attributeNames()
Return an enumeration over the names of the attributes in this schematic. There is no order guarantee on the attributes. 
- 
containsElement
public boolean containsElement(XmlElement elt)
Test if this element contains the given element. This is included mainly to allow test suites to be written. In general, check the parent of the child. 
- 
elementCount
public int elementCount()
Return the number of child elements. 
- 
elements
public java.util.Iterator elements()
Return an Iterator of all the child elements of this element. The elements are generated in the order in which they were added. 
- 
elements
public java.util.Iterator elements(java.lang.String type)
Return an Iterator of all the child elements of this element that have the given element type.- Returns:
 - an Iterator of XmlElements
 
 
- 
getAttribute
public java.lang.String getAttribute(java.lang.String name)
Return the value of the attribute with the given name, or null if there isn't one. 
- 
getAttributeMap
public java.util.Map getAttributeMap()
Return the map from attribute names to value. This returns the internal object that holds attributes, and is provided so that more sophisticated operations than provided by the methods in this interface can be implemented when needed. Note: if you add any attributes to this list, you must be sure that the value is a String. 
- 
getChildList
public java.util.List getChildList()
Return the list of child elements. This returns the internal object that holds child elements, and is provided so that more sophisticated operations than provided by the methods in this interface can be implemented when needed. Note: if you add any elements to this list, you MUST call the setParent() method of that element with this object. 
- 
getElement
public XmlElement getElement(java.lang.String type)
Return the first child element of this element with the given type, or null if there isn't one. 
- 
getElement
public XmlElement getElement(java.lang.String type, java.lang.String name)
Return the first child element of this element with the given type and name, or null if there isn't one. 
- 
getType
public java.lang.String getType()
Return the type of this XmlElement. The type is immutably set when the XmlElement is created. 
- 
getParent
public XmlElement getParent()
Return the parent element of this element, or null if it has no parent. 
- 
getPCData
public java.lang.String getPCData()
Return the PCData that is associated with this XmlElement. 
- 
hasAttribute
public boolean hasAttribute(java.lang.String name)
Test if this element has the attribute with the given name. 
- 
removeAttribute
public void removeAttribute(java.lang.String name)
Remove an attribute from this element. 
- 
removeElement
public void removeElement(XmlElement e)
Remove a child element from this element. 
- 
setAttribute
public void setAttribute(java.lang.String name, java.lang.String value)Set the attribute with the given name to the given value. Throw an exception if there is no attribute with the given name in this schematic. 
- 
setParent
public void setParent(XmlElement p)
Set the parent element of this element. 
- 
setPCData
public void setPCData(java.lang.String s)
Set the text of this element to the given string. 
- 
setType
public void setType(java.lang.String s)
Set the type of this element. 
- 
toString
public java.lang.String toString()
Convert this element to a string in XML.- Overrides:
 toStringin classjava.lang.Object
 
- 
writeXML
public void writeXML(java.io.Writer out, java.lang.String prefix) throws java.io.IOExceptionPrint this element to a Writer.- Throws:
 java.io.IOException
 
 - 
 
 -