Methods Summary |
---|
public void | clear()removes all children and attributes
attributes = null;
children = null;
|
public org.kxml2.kdom.Element | createElement(java.lang.String namespace, java.lang.String name)Forwards creation request to parent if any, otherwise
calls super.createElement.
return (this.parent == null)
? super.createElement(namespace, name)
: this.parent.createElement(namespace, name);
|
public int | getAttributeCount()Returns the number of attributes of this element.
return attributes == null ? 0 : attributes.size();
|
public java.lang.String | getAttributeName(int index)
return ((String []) attributes.elementAt (index)) [1];
|
public java.lang.String | getAttributeNamespace(int index)
return ((String []) attributes.elementAt (index)) [0];
|
public java.lang.String | getAttributeValue(int index)
return ((String []) attributes.elementAt (index)) [2];
|
public java.lang.String | getAttributeValue(java.lang.String namespace, java.lang.String name)
for (int i = 0; i < getAttributeCount (); i++) {
if (name.equals (getAttributeName (i))
&& (namespace == null || namespace.equals (getAttributeNamespace(i)))) {
return getAttributeValue (i);
}
}
return null;
|
public java.lang.String | getName()returns the (local) name of the element
return name;
|
public java.lang.String | getNamespace()returns the namespace of the element
return namespace;
|
public int | getNamespaceCount()returns the number of declared namespaces, NOT including
parent elements
return (prefixes == null ? 0 : prefixes.size ());
|
public java.lang.String | getNamespacePrefix(int i)
return ((String []) prefixes.elementAt (i)) [0];
|
public java.lang.String | getNamespaceUri(java.lang.String prefix)returns the namespace for the given prefix
int cnt = getNamespaceCount ();
for (int i = 0; i < cnt; i++) {
if (prefix == getNamespacePrefix (i) ||
(prefix != null && prefix.equals (getNamespacePrefix (i))))
return getNamespaceUri (i);
}
return parent instanceof Element ? ((Element) parent).getNamespaceUri (prefix) : null;
|
public java.lang.String | getNamespaceUri(int i)
return ((String []) prefixes.elementAt (i)) [1];
|
public org.kxml2.kdom.Node | getParent()Returns the parent node of this element
return parent;
|
public org.kxml2.kdom.Node | getRoot()Returns the root node, determined by ascending to the
all parents un of the root element.
Element current = this;
while (current.parent != null) {
if (!(current.parent instanceof Element)) return current.parent;
current = (Element) current.parent;
}
return current;
|
public void | init()called when all properties are set, but before children
are parsed. Please do not use setParent for initialization
code any longer.
|
public void | parse(org.xmlpull.v1.XmlPullParser parser)Builds the child elements from the given Parser. By overwriting
parse, an element can take complete control over parsing its
subtree.
for (int i = parser.getNamespaceCount (parser.getDepth () - 1);
i < parser.getNamespaceCount (parser.getDepth ()); i++) {
setPrefix (parser.getNamespacePrefix (i), parser.getNamespaceUri(i));
}
for (int i = 0; i < parser.getAttributeCount (); i++)
setAttribute (parser.getAttributeNamespace (i),
// parser.getAttributePrefix (i),
parser.getAttributeName (i),
parser.getAttributeValue (i));
// if (prefixMap == null) throw new RuntimeException ("!!");
init();
if (parser.isEmptyElementTag())
parser.nextToken ();
else {
parser.nextToken ();
super.parse(parser);
if (getChildCount() == 0)
addChild(IGNORABLE_WHITESPACE, "");
}
parser.require(
XmlPullParser.END_TAG,
getNamespace(),
getName());
parser.nextToken ();
|
public void | setAttribute(java.lang.String namespace, java.lang.String name, java.lang.String value)Sets the given attribute; a value of null removes the attribute
if (attributes == null)
attributes = new Vector ();
if (namespace == null)
namespace = "";
for (int i = attributes.size()-1; i >=0; i--){
String[] attribut = (String[]) attributes.elementAt(i);
if (attribut[0].equals(namespace) &&
attribut[1].equals(name)){
if (value == null) {
attributes.removeElementAt(i);
}
else {
attribut[2] = value;
}
return;
}
}
attributes.addElement
(new String [] {namespace, name, value});
|
public void | setName(java.lang.String name)sets the name of the element
this.name = name;
|
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.
if (namespace == null)
throw new NullPointerException ("Use \"\" for empty namespace");
this.namespace = namespace;
|
protected void | setParent(org.kxml2.kdom.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!
this.parent = parent;
|
public void | setPrefix(java.lang.String prefix, java.lang.String namespace)Sets the given prefix; a namespace value of null removess the
prefix
if (prefixes == null) prefixes = new Vector ();
prefixes.addElement (new String [] {prefix, namespace});
|
public void | write(org.xmlpull.v1.XmlSerializer writer)Writes this element and all children to the given XmlWriter.
if (prefixes != null) {
for (int i = 0; i < prefixes.size(); i++) {
writer.setPrefix (getNamespacePrefix (i), getNamespaceUri (i));
}
}
writer.startTag(
getNamespace(),
getName());
int len = getAttributeCount();
for (int i = 0; i < len; i++) {
writer.attribute(
getAttributeNamespace(i),
getAttributeName(i),
getAttributeValue(i));
}
writeChildren(writer);
writer.endTag(getNamespace (), getName ());
|