summaryrefslogtreecommitdiffstats
path: root/xml/src/main/java/org/kxml2/kdom/Element.java
diff options
context:
space:
mode:
Diffstat (limited to 'xml/src/main/java/org/kxml2/kdom/Element.java')
-rw-r--r--xml/src/main/java/org/kxml2/kdom/Element.java98
1 files changed, 49 insertions, 49 deletions
diff --git a/xml/src/main/java/org/kxml2/kdom/Element.java b/xml/src/main/java/org/kxml2/kdom/Element.java
index 6a5777b..a9cb426 100644
--- a/xml/src/main/java/org/kxml2/kdom/Element.java
+++ b/xml/src/main/java/org/kxml2/kdom/Element.java
@@ -25,7 +25,7 @@ import java.util.*;
import org.xmlpull.v1.*;
-/**
+/**
* 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. */
@@ -41,7 +41,7 @@ public class Element extends Node {
public Element() {
}
- /**
+ /**
* called when all properties are set, but before children
* are parsed. Please do not use setParent for initialization
* code any longer. */
@@ -52,7 +52,7 @@ public class Element extends Node {
- /**
+ /**
* removes all children and attributes */
public void clear() {
@@ -60,20 +60,20 @@ public class Element extends Node {
children = null;
}
- /**
+ /**
* Forwards creation request to parent if any, otherwise
* calls super.createElement. */
public Element createElement(
String namespace,
- String name) {
+ String name) {
return (this.parent == null)
? super.createElement(namespace, name)
: this.parent.createElement(namespace, name);
}
- /**
+ /**
* Returns the number of attributes of this element. */
public int getAttributeCount() {
@@ -91,47 +91,47 @@ public class Element extends Node {
public String getAttributeName (int index) {
return ((String []) attributes.elementAt (index)) [1];
}
-
+
public String getAttributeValue (int index) {
return ((String []) attributes.elementAt (index)) [2];
}
-
-
+
+
public String getAttributeValue (String namespace, String name) {
for (int i = 0; i < getAttributeCount (); i++) {
- if (name.equals (getAttributeName (i))
+ if (name.equals (getAttributeName (i))
&& (namespace == null || namespace.equals (getAttributeNamespace(i)))) {
return getAttributeValue (i);
}
- }
- return null;
+ }
+ return null;
}
- /**
- * Returns the root node, determined by ascending to the
+ /**
+ * Returns the root node, determined by ascending to the
* all parents un of the root element. */
public Node getRoot() {
Element current = this;
-
+
while (current.parent != null) {
if (!(current.parent instanceof Element)) return current.parent;
current = (Element) current.parent;
}
-
+
return current;
}
- /**
+ /**
* returns the (local) name of the element */
public String getName() {
return name;
}
- /**
+ /**
* returns the namespace of the element */
public String getNamespace() {
@@ -139,21 +139,21 @@ public class Element extends Node {
}
- /**
+ /**
* returns the namespace for the given prefix */
-
+
public String getNamespaceUri (String 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 getNamespaceUri (i);
}
return parent instanceof Element ? ((Element) parent).getNamespaceUri (prefix) : null;
}
- /**
+ /**
* returns the number of declared namespaces, NOT including
* parent elements */
@@ -171,15 +171,15 @@ public class Element extends Node {
}
- /**
+ /**
* Returns the parent node of this element */
public Node getParent() {
return parent;
}
- /*
- * Returns the parent element if available, null otherwise
+ /*
+ * Returns the parent element if available, null otherwise
public Element getParentElement() {
return (parent instanceof Element)
@@ -188,9 +188,9 @@ public class Element extends Node {
}
*/
- /**
- * Builds the child elements from the given Parser. By overwriting
- * parse, an element can take complete control over parsing its
+ /**
+ * Builds the child elements from the given Parser. By overwriting
+ * parse, an element can take complete control over parsing its
* subtree. */
public void parse(XmlPullParser parser)
@@ -200,9 +200,9 @@ public class Element extends Node {
i < parser.getNamespaceCount (parser.getDepth ()); i++) {
setPrefix (parser.getNamespacePrefix (i), parser.getNamespaceUri(i));
}
-
-
- for (int i = 0; i < parser.getAttributeCount (); i++)
+
+
+ for (int i = 0; i < parser.getAttributeCount (); i++)
setAttribute (parser.getAttributeNamespace (i),
// parser.getAttributePrefix (i),
parser.getAttributeName (i),
@@ -214,7 +214,7 @@ public class Element extends Node {
init();
- if (parser.isEmptyElementTag())
+ if (parser.isEmptyElementTag())
parser.nextToken ();
else {
parser.nextToken ();
@@ -223,76 +223,76 @@ public class Element extends Node {
if (getChildCount() == 0)
addChild(IGNORABLE_WHITESPACE, "");
}
-
+
parser.require(
XmlPullParser.END_TAG,
getNamespace(),
getName());
-
+
parser.nextToken ();
}
- /**
+ /**
* Sets the given attribute; a value of null removes the attribute */
public void setAttribute (String namespace, String name, String value) {
- if (attributes == null)
+ if (attributes == null)
attributes = new Vector ();
- if (namespace == null)
+ 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;
+ return;
}
}
- attributes.addElement
+ attributes.addElement
(new String [] {namespace, name, value});
}
- /**
- * Sets the given prefix; a namespace value of null removess the
+ /**
+ * Sets the given prefix; a namespace value of null removess the
* prefix */
public void setPrefix (String prefix, String namespace) {
if (prefixes == null) prefixes = new Vector ();
- prefixes.addElement (new String [] {prefix, namespace});
+ prefixes.addElement (new String [] {prefix, namespace});
}
- /**
+ /**
* sets the name of the element */
public void setName(String name) {
this.name = name;
}
- /**
+ /**
* 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. */
public void setNamespace(String namespace) {
- if (namespace == null)
+ if (namespace == null)
throw new NullPointerException ("Use \"\" for empty namespace");
this.namespace = namespace;
}
- /**
+ /**
* 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
@@ -303,7 +303,7 @@ public class Element extends Node {
}
- /**
+ /**
* Writes this element and all children to the given XmlWriter. */
public void write(XmlSerializer writer)