Object XmlElement
XmlElement objects represent elements in XML documents
Inheritance
Member attributes
namespaceURI
String, the URI of the namespace of the query element. If the selected node has no namespace, this attribute returns NULL
1readonly String XmlElement.namespaceURI;
prefix
String, query and set the namespace prefix of the element. If the selected node has no namespace, this attribute returns NULL
1String XmlElement.prefix;
localName
String, the local name of the query element. If the selected node has no namespace, this attribute is equivalent to nodeName
1readonly String XmlElement.localName;
tagName
String, returns the tag name of the element
1readonly String XmlElement.tagName;
id
String, query and set the id attribute of the element
1String XmlElement.id;
textContent
String, query and set the text of the selected element. When querying, return the values of all text nodes in the element node; when setting, delete all child nodes and replace them with a single text node.
1String XmlElement.textContent;
innerHTML
String, query and set the HTML text of the selected element, only valid in html mode. When querying, return the HTML code of all child nodes in the element node; when setting, delete all child nodes and replace them with the specified HTML after decoding.
1String XmlElement.innerHTML;
className
String, query and set the class attribute of the element, only valid in html mode
1String XmlElement.className;
attributes
XmlNamedNodeMap, Returns the NamedNodeMap containing the attributes of the selected node. If the selected node is not an element, this attribute returns NULL.
1readonly XmlNamedNodeMap XmlElement.attributes;
nodeType
Integer, returns the node type of the node
1readonly Integer XmlElement.nodeType;
The nodeType of different objects will return different values:
- XmlElement: ELEMENT_NODE(1)
- XmlAttr: ATTRIBUTE_NODE(2)
- XmlText: TEXT_NODE(3)
- XmlCDATASection: CDATA_SECTION_NODE(4)
- XmlProcessingInstruction: PROCESSING_INSTRUCTION_NODE(7)
- XmlComment: COMMENT_NODE(8)
- XmlDocument: DOCUMENT_NODE(9)
- XmlDocumentType: DOCUMENT_TYPE_NODE(10)
nodeName
String, returns the name of the node, according to its type
1readonly String XmlElement.nodeName;
The nodeName of different objects will return different values:
- XmlElement: element name
- XmlAttr: Property name
- XmlText: #text
- XmlCDATASection: #cdata-section
- XmlProcessingInstruction: Return to the specified target
- XmlComment: #comment
- XmlDocument: #document
- XmlDocumentType: doctype name
nodeValue
String, returns the name of the node, according to its type
1String XmlElement.nodeValue;
The nodeName of different objects will return different values:
- XmlElement: null
- XmlAttr: The value of the attribute
- XmlText: The content of the node
- XmlCDATASection: The content of the node
- XmlProcessingInstruction: Return the specified content data
- XmlComment: Comment text
- XmlDocument: null
- XmlDocumentType: null
ownerDocument
XmlDocument, Returns the root element of the node (XmlDocument Object)
1readonly XmlDocument XmlElement.ownerDocument;
parentNode
XmlNode, Can return the parent node of a node
1readonly XmlNode XmlElement.parentNode;
childNodes
XmlNodeList, Returns the node list of the child nodes of the specified node
1readonly XmlNodeList XmlElement.childNodes;
firstChild
XmlNode, Return the first child node of the node
1readonly XmlNode XmlElement.firstChild;
lastChild
XmlNode, Return the last child node of the node
1readonly XmlNode XmlElement.lastChild;
previousSibling
XmlNode, Returns the node immediately before a certain node (at the same tree level), if there is no such node, then the attribute returns null
1readonly XmlNode XmlElement.previousSibling;
nextSibling
XmlNode, Returns the node immediately following an element (in the same tree level), if there is no such node, the property returns null
1readonly XmlNode XmlElement.nextSibling;
Member function
getAttribute
Query the value of an attribute by name
1String XmlElement.getAttribute(String name);
Call parameters:
- name: String, specify the attribute name of the query
Return result:
- String, Returns the value of the attribute
getAttributeNS
Get attribute value by namespace URI and name
1
2String XmlElement.getAttributeNS(String namespaceURI,
String localName);
Call parameters:
- namespaceURI: String, specify the namespace URI of the query
- localName: String, specify the attribute name of the query
Return result:
- String, Returns the value of the attribute
setAttribute
Create or change a new property
1
2XmlElement.setAttribute(String name,
String value);
Call parameters:
- name: String, specify the name of the property to be set
- value: String, specify the attribute value to be set
This method sets the specified attribute to the specified value. If there is no attribute with the specified name, the method will create a new attribute
setAttributeNS
Create or change attributes with namespace
1
2
3XmlElement.setAttributeNS(String namespaceURI,
String qualifiedName,
String value);
Call parameters:
- namespaceURI: String, specify the namespace URI to be set
- qualifiedName: String, specify the name of the property to be set
- value: String, specify the attribute value to be set
This method is similar to the setAttribute method, except that the attribute to be created or set is specified by the namespace URI and the qualified name (consisting of the namespace prefix, colon, and local name in the namespace). In addition to changing the value of an attribute, using this method can also change the namespace prefix of the attribute
removeAttribute
Delete the specified attribute by name
1XmlElement.removeAttribute(String name);
Call parameters:
- name: String, specify the name of the deleted attribute
removeAttributeNS
Delete specified attributes by namespace and name
1
2XmlElement.removeAttributeNS(String namespaceURI,
String localName);
Call parameters:
- namespaceURI: String, specify the namespace URI to be deleted
- localName: String, specify the name of the deleted attribute
hasAttribute
Query whether the current node has an attribute with the specified name
1Boolean XmlElement.hasAttribute(String name);
Call parameters:
- name: String, specify the attribute name of the query
Return result:
- Boolean, If the current element node has the specified attribute, it returns true, otherwise it returns false
hasAttributeNS
Query whether the current node has attributes of the specified namespace and name
1
2Boolean XmlElement.hasAttributeNS(String namespaceURI,
String localName);
Call parameters:
- namespaceURI: String, specify the namespace URI to be queried
- localName: String, specify the attribute name of the query
Return result:
- Boolean, If the current element node has the specified attribute, it returns true, otherwise it returns false
getElementsByTagName
Returns all elements with the specified name XmlNodeList
1XmlNodeList XmlElement.getElementsByTagName(String tagName);
Call parameters:
- tagName: String, the label name to be retrieved. The value "*" matches all tags
Return result:
- XmlNodeList, Of the XmlElement node with the specified mark in the node tree XmlNodeListgather. The order of returned element nodes is the order in which they appear in the source document.
This method will traverse the descendants of the specified element and return an XmlElement node XmlNodeListObject, which means all document elements with the specified tag name. The order of the elements in the returned array is the order in which they appear in the document source code.
XmlDocument The interface also defines the getElementsByTagName method, which is similar to this method, but traverses the entire document instead of traversing the descendants of an element.
getElementsByTagNameNS
Return all elements with the specified namespace and name XmlNodeList
1
2XmlNodeList XmlElement.getElementsByTagNameNS(String namespaceURI,
String localName);
Call parameters:
- namespaceURI: String, specify the namespace URI to be queried
- localName: String, the label name to be retrieved. The value "*" matches all tags
Return result:
- XmlNodeList, Of the XmlElement node with the specified mark in the node tree XmlNodeListgather. The order of returned element nodes is the order in which they appear in the source document.
This method is similar to the getElementsByTagName method, except that the tag name of the element you want to get is specified as a combination of the namespace URI and the local name defined in the namespace.
getElementById
Returns the element with the specified id attribute
1XmlElement XmlElement.getElementById(String id);
Call parameters:
- id: String, id to be retrieved
Return result:
- XmlElement, XmlElement node with the specified id attribute in the node tree
This method will traverse the descendant nodes of the specified element and return an XmlElement node object representing the first document element with the specified id attribute. .
XmlDocument The interface also defines the getElementsByTagName method, which is similar to this method, but traverses the entire document instead of traversing the descendants of an element.
getElementsByClassName
Returns a node list of all elements with the specified class name
1XmlNodeList XmlElement.getElementsByClassName(String className);
Call parameters:
- className: String, the name of the class to be retrieved
Return result:
- XmlNodeList, The XmlElement node with the specified class name in the document tree XmlNodeListgather. The order of returned element nodes is the order in which they appear in the source document.
This method will return a XmlNodeList Object (can be treated as a read-only array). This object stores all XmlElement nodes with the specified class name in the document. The order in which they are stored is the order in which they appear in the source document. XmlNodeList The object is "live", that is, if an element with the specified tag name is added or deleted in the document, its content will automatically be updated as necessary.
hasChildNodes
Query whether there are child nodes
1Boolean XmlElement.hasChildNodes();
Return result:
- Boolean, Return true if there are any child nodes, otherwise return false
normalize
Merge adjacent Text nodes and delete empty Text nodes
1XmlElement.normalize();
This method will traverse all descendant nodes of the current node, and normalize the document by deleting the empty Text node and merging all adjacent Text nodes. This method is useful for simplifying the structure of the document tree after inserting or deleting nodes.
cloneNode
Create an exact copy of the specified node
1XmlNode XmlElement.cloneNode(Boolean deep = true);
Call parameters:
- deep: Boolean, whether to deep copy, when true, the cloned node will clone all child nodes of the original node
Return result:
- XmlNode, Return the copied node
This method will copy and return a copy of the node that called it. If the parameter passed to it is true, it will also recursively copy all descendants of the current node. Otherwise, it only copies the current node. The returned node does not belong to the document tree, and its parentNode property is null. When the Element node is copied, all its attributes will be copied.
lookupPrefix
Returns the prefix matching the specified namespace URI on the current node
1String XmlElement.lookupPrefix(String namespaceURI);
Call parameters:
- namespaceURI: String, specify the matching namespace URI
Return result:
- String, Returns the matched prefix, returns null if it is not matched
lookupNamespaceURI
Returns the namespace URI that matches the specified prefix on the current node
1String XmlElement.lookupNamespaceURI(String prefix);
Call parameters:
- prefix: String, specify the matching prefix
Return result:
- String, Returns the matching namespace URI, returns null if it is not matched
insertBefore
Insert a new child node before the existing child node
1
2XmlNode XmlElement.insertBefore(XmlNode newChild,
XmlNode refChild);
Call parameters:
Return result:
- XmlNode, Return the new child node
If newChild already exists in the document tree, it will be deleted from the document tree and then reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. In other words, the ownerDocument property of newChild must be the same as the ownerDocument property of the current node.
insertAfter
Insert a new child node after the existing child node
1
2XmlNode XmlElement.insertAfter(XmlNode newChild,
XmlNode refChild);
Call parameters:
Return result:
- XmlNode, Return the new child node
If newChild already exists in the document tree, it will be deleted from the document tree and then reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. In other words, the ownerDocument property of newChild must be the same as the ownerDocument property of the current node.
appendChild
Add a new child node to the end of the node's child node list
1XmlNode XmlElement.appendChild(XmlNode newChild);
Call parameters:
- newChild: XmlNode, Specify the added node
Return result:
- XmlNode, Return this new child node
If newChild already exists in the document tree, it will be deleted from the document tree and then reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. In other words, the ownerDocument property of newChild must be the same as the ownerDocument property of the current node.
replaceChild
Replace one child node with another
1
2XmlNode XmlElement.replaceChild(XmlNode newChild,
XmlNode oldChild);
Call parameters:
Return result:
- XmlNode, If the replacement is successful, this method can return the replaced node, if the replacement fails, it returns null
If newChild already exists in the document tree, it will be deleted from the document tree and then reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. In other words, the ownerDocument property of newChild must be the same as the ownerDocument property of the current node.
removeChild
Remove a node from the list of child nodes
1XmlNode XmlElement.removeChild(XmlNode oldChild);
Call parameters:
- oldChild: XmlNode, Specify the node to be deleted
Return result:
- XmlNode, If the deletion is successful, this method can return the deleted node, if it fails, it returns null
toString
Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics
1String XmlElement.toString();
Return result:
- String, Returns the string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object
1Value XmlElement.toJSON(String key = "");
Call parameters:
- key: String, unused
Return result:
- Value, Returns a value containing JSON serializable