org.kxml.kdom
Class Element

java.lang.Object
  extended byorg.kxml.kdom.Node
      extended byorg.kxml.kdom.Element
All Implemented Interfaces:
XmlIO

public class Element
extends Node

In order to create an element, please use the createElement method instead of invoking the constructor directly. The right place to add user defined initialization code is the init method.


Field Summary
protected  java.util.Vector attributes
           
protected  java.lang.String name
           
protected  java.lang.String namespace
           
protected  Node parent
           
protected  PrefixMap prefixMap
           
 
Fields inherited from class org.kxml.kdom.Node
children, types
 
Constructor Summary
Element()
           
 
Method Summary
 void clear()
          removes all children and attributes
 Element createElement(java.lang.String namespace, java.lang.String name)
          Forwards creation request to parent if any, otherwise calls super.createElement.
 Attribute getAttribute(int index)
          Returns the attribute at the given index.
 Attribute getAttribute(java.lang.String name)
          convenience method for getAttribute (Xml.NO_NAMESPACE, name)
 Attribute getAttribute(java.lang.String namespace, java.lang.String name)
          returns the attribute with the given namespace and name.
 int getAttributeCount()
          Returns the number of attributes of this element.
 java.util.Vector getAttributes()
          Returns a Vector containing all Attributes.
 Document getDocument()
          Returns the document this element is a member of.
 java.lang.String getName()
          returns the (local) name of the element
 java.lang.String getNamespace()
          returns the namespace of the element
 Node getParent()
          Returns the parent node of this element
 Element getParentElement()
          Returns the parent element if available, null otherwise
 PrefixMap getPrefixMap()
          Returns the namespace prefix map of this Element.
 java.lang.String getValue(java.lang.String name)
          Returns the value of the given attribute.
 java.lang.String getValueDefault(java.lang.String name, java.lang.String dflt)
          Returns the value of the given attribute, or the given default value if the desired attribute does not exist.
 Element init(Node parent, java.lang.String namespace, java.lang.String name, java.util.Vector attributes)
          Deprecated. The init method is invoked by createElement setParent .
 void parse(AbstractXmlParser parser)
          Builds the child elements from the given Parser.
 void removeAttribute(int index)
          Removes the attribute at the given index
 void setAttribute(Attribute attribute)
          sets the given attribute
 void setAttributes(java.util.Vector attributes)
          Replaces all attributes by the given Vector.
 void setName(java.lang.String name)
          sets the name of the element
 void setNamespace(java.lang.String namespace)
          sets the namespace of the element.
protected  void setParent(Node parent)
          Sets the Parent of this element.
 void setPrefixMap(PrefixMap prefixMap)
          Sets the namespace prefix map of this Node.
 void setValue(java.lang.String name, java.lang.String value)
          sets the value of the given attribute to the given string.
 void write(AbstractXmlWriter writer)
          Writes this element and all children to the given XmlWriter.
 
Methods inherited from class org.kxml.kdom.Node
addChild, addChild, getChild, getChildCount, getElement, getElement, getElement, getText, getText, getType, indexOf, indexOf, removeChild, toString, writeChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

namespace

protected java.lang.String namespace

name

protected java.lang.String name

attributes

protected java.util.Vector attributes

parent

protected Node parent

prefixMap

protected PrefixMap prefixMap
Constructor Detail

Element

public Element()
Method Detail

init

public Element init(Node parent,
                    java.lang.String namespace,
                    java.lang.String name,
                    java.util.Vector attributes)
Deprecated. The init method is invoked by createElement setParent .


clear

public void clear()
removes all children and attributes


createElement

public Element createElement(java.lang.String namespace,
                             java.lang.String name)
Forwards creation request to parent if any, otherwise calls super.createElement. 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.

Overrides:
createElement in class Node

getAttribute

public Attribute getAttribute(int index)
Returns the attribute at the given index.


getAttribute

public Attribute getAttribute(java.lang.String name)
convenience method for getAttribute (Xml.NO_NAMESPACE, name)


getAttribute

public Attribute getAttribute(java.lang.String namespace,
                              java.lang.String name)
returns the attribute with the given namespace and name. Please use null as placeholder for any namespace or Xml.NO_NAMESPACE for no namespace.


getAttributeCount

public int getAttributeCount()
Returns the number of attributes of this element.


getAttributes

public java.util.Vector getAttributes()
Returns a Vector containing all Attributes. The Vector is not copied. Modification is not allowed.


getDocument

public Document getDocument()
Returns the document this element is a member of. The document is determined by ascending to the parent of the root element. If the element is not contained in a document, null is returned.


getName

public java.lang.String getName()
returns the (local) name of the element

Overrides:
getName in class Node

getNamespace

public java.lang.String getNamespace()
returns the namespace of the element

Overrides:
getNamespace in class Node

getParent

public Node getParent()
Returns the parent node of this element


getParentElement

public Element getParentElement()
Returns the parent element if available, null otherwise


getPrefixMap

public PrefixMap getPrefixMap()
Returns the namespace prefix map of this Element.


getValue

public java.lang.String getValue(java.lang.String name)
Returns the value of the given attribute. If the attribute does not exist, an exception is thrown. If a null value shall be returned for not existing attributes, please use getValueDefault (name, null) instead.


getValueDefault

public java.lang.String getValueDefault(java.lang.String name,
                                        java.lang.String dflt)
Returns the value of the given attribute, or the given default value if the desired attribute does not exist.


parse

public void parse(AbstractXmlParser parser)
           throws java.io.IOException
Builds the child elements from the given Parser. By overwriting parse, an element can take complete control over parsing its subtree.

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

removeAttribute

public void removeAttribute(int index)
Removes the attribute at the given index


setAttributes

public void setAttributes(java.util.Vector attributes)
Replaces all attributes by the given Vector. Caution: The Vector is not copied.


setAttribute

public void setAttribute(Attribute attribute)
sets the given attribute


setValue

public void setValue(java.lang.String name,
                     java.lang.String value)
sets the value of the given attribute to the given string. Convenience method for setAttribute (new Attribute (name, value));


setName

public void setName(java.lang.String name)
sets the name of the element


setNamespace

public void setNamespace(java.lang.String namespace)
sets the namespace of the element. 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.


setParent

protected void setParent(Node parent)
Sets the Parent of this element. Automatically called from the add method. The right place for replacements of the deprectated init method. Please use with care, you can simply create inconsitencies in the document tree structure using this method!


setPrefixMap

public void setPrefixMap(PrefixMap prefixMap)
Sets the namespace prefix map of this Node.


write

public void write(AbstractXmlWriter writer)
           throws java.io.IOException
Writes this element and all children to the given XmlWriter.

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