In the DOM, everything in an XML document is a node.
XML DOM Nodes
According to the DOM, everything in an XML document is a node.
The DOM says:
- The entire document is a document node
- Every XML element is an element node
- The text in the XML elements are text nodes
- Every attribute is an attribute node
- Comments are comment nodes
XmlNode Class
Use the XmlNode
class to work with a node in an XML document.XmlNode Methods
The following are methods for XmlNode
. All are instance methods.
addChildElement(name, namespace, prefix)
Creates a child element node for this node.addCommentNode(text)
Creates a child comment node for this node.addTextNode(text)
Creates a child text node for this node.getAttribute(key, keyNamespace)
Returns namespacePrefix:attributeValue for the given key and key namespace.getAttributeCount()
Returns the number of attributes for this node.getAttributeKeyAt(index)
Returns the attribute key for the given index. Index values start at 0.getAttributeKeyNsAt(index)
Returns the attribute key namespace for the given index.getAttributeValue(key, keyNamespace)
Returns the attribute value for the given key and key namespace.getAttributeValueNs(key, keyNamespace)
Returns the attribute value namespace for the given key and key namespace.getChildElement(name, namespace)
Returns the child element node for the node with the given name and namespace.getChildElements()
Returns the child element nodes for this node. This doesn't include child text or comment nodes.getChildren()
Returns the child nodes for this node. This includes all node types.getName()
Returns the element name.getNamespace()
Returns the namespace of the element.getNamespaceFor(prefix)
Returns the namespace of the element for the given prefix.getNodeType()
Returns the node type.getParent()
Returns the parent of this element.getPrefixFor(namespace)
Returns the prefix of the given namespace.getText()
Returns the text for this node.removeAttribute(key, keyNamespace)
Removes the attribute with the given key and key namespace. Returns true if successful, false otherwise.removeChild(childNode)
Removes the given child node.setAttribute(key, value)
Sets the key attribute value.setAttributeNs(key, value, keyNamespace, valueNamespace)
Sets the key attribute value.setNamespace(prefix, namespace)
Sets the namespace for the given prefix.