Package org.kxml2.kdom
Class Element
- java.lang.Object
-
- org.kxml2.kdom.Node
-
- org.kxml2.kdom.Element
-
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
Fields Modifier and Type Field Description protected Vectorattributesprotected Stringnameprotected Stringnamespaceprotected Nodeparentprotected Vectorprefixes-
Fields inherited from class org.kxml2.kdom.Node
CDSECT, children, COMMENT, DOCDECL, DOCUMENT, ELEMENT, ENTITY_REF, IGNORABLE_WHITESPACE, PROCESSING_INSTRUCTION, TEXT, types
-
-
Constructor Summary
Constructors Constructor Description Element()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()removes all children and attributesElementcreateElement(String namespace, String name)Forwards creation request to parent if any, otherwise calls super.createElement.intgetAttributeCount()Returns the number of attributes of this element.StringgetAttributeName(int index)StringgetAttributeNamespace(int index)StringgetAttributeValue(int index)StringgetAttributeValue(String namespace, String name)StringgetName()returns the (local) name of the elementStringgetNamespace()returns the namespace of the elementintgetNamespaceCount()returns the number of declared namespaces, NOT including parent elementsStringgetNamespacePrefix(int i)StringgetNamespaceUri(int i)StringgetNamespaceUri(String prefix)returns the namespace for the given prefixNodegetParent()Returns the parent node of this elementNodegetRoot()Returns the root node, determined by ascending to the all parents un of the root element.voidinit()called when all properties are set, but before children are parsed.voidparse(XmlPullParser parser)Builds the child elements from the given Parser.voidsetAttribute(String namespace, String name, String value)Sets the given attribute; a value of null removes the attributevoidsetName(String name)sets the name of the elementvoidsetNamespace(String namespace)sets the namespace of the element.protected voidsetParent(Node parent)Sets the Parent of this element.voidsetPrefix(String prefix, String namespace)Sets the given prefix; a namespace value of null removess the prefixvoidwrite(XmlSerializer writer)Writes this element and all children to the given XmlWriter.-
Methods inherited from class org.kxml2.kdom.Node
addChild, addChild, getChild, getChildCount, getElement, getElement, getText, getType, indexOf, isText, removeChild, writeChildren
-
-
-
-
Method Detail
-
init
public void init()
called when all properties are set, but before children are parsed. Please do not use setParent for initialization code any longer.
-
clear
public void clear()
removes all children and attributes
-
createElement
public Element createElement(String namespace, String name)
Forwards creation request to parent if any, otherwise calls super.createElement.- Overrides:
createElementin classNode
-
getAttributeCount
public int getAttributeCount()
Returns the number of attributes of this element.
-
getAttributeNamespace
public String getAttributeNamespace(int index)
-
getAttributeName
public String getAttributeName(int index)
-
getAttributeValue
public String getAttributeValue(int index)
-
getRoot
public Node getRoot()
Returns the root node, determined by ascending to the all parents un of the root element.
-
getName
public String getName()
returns the (local) name of the element
-
getNamespace
public String getNamespace()
returns the namespace of the element
-
getNamespaceUri
public String getNamespaceUri(String prefix)
returns the namespace for the given prefix
-
getNamespaceCount
public int getNamespaceCount()
returns the number of declared namespaces, NOT including parent elements
-
getNamespacePrefix
public String getNamespacePrefix(int i)
-
getNamespaceUri
public String getNamespaceUri(int i)
-
getParent
public Node getParent()
Returns the parent node of this element
-
parse
public void parse(XmlPullParser parser) throws IOException, XmlPullParserException
Builds the child elements from the given Parser. By overwriting parse, an element can take complete control over parsing its subtree.- Overrides:
parsein classNode- Throws:
IOExceptionXmlPullParserException
-
setAttribute
public void setAttribute(String namespace, String name, String value)
Sets the given attribute; a value of null removes the attribute
-
setPrefix
public void setPrefix(String prefix, String namespace)
Sets the given prefix; a namespace value of null removess the prefix
-
setName
public void setName(String name)
sets the name of the element
-
setNamespace
public void setNamespace(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. Please use with care, you can simply create inconsitencies in the document tree structure using this method!
-
write
public void write(XmlSerializer writer) throws IOException
Writes this element and all children to the given XmlWriter.- Overrides:
writein classNode- Throws:
IOException
-
-