Object built-in object

ObjectXmlElement

XmlElement objects represent elements in an XML document

inheritance relationship

member properties

namespaceURI

String, URI of the namespace of the query element. If the selected node has no namespace, this property returns NULL

1
readonly String XmlElement.namespaceURI;

prefix

String, query and set the namespace prefix of the element. If the selected node has no namespace, this property returns NULL

1
String XmlElement.prefix;

localName

String, the local name of the query element. If the selected node has no namespace, this property is equivalent to nodeName

1
readonly String XmlElement.localName;

tagName

String, returns the tag name of the element

1
readonly String XmlElement.tagName;

id

String, query and set the id attribute of the element

1
String XmlElement.id;

innerHTML

String, query and set the HTML text of the descendants of the selected element, only valid in html mode. When querying, return the HTML encoding of all child nodes within the element node; when setting, delete all child nodes and replace them with the specified HTML decoding.

1
String XmlElement.innerHTML;

outerHTML

String, query the HTML text of the selected element and its descendants, only valid in html mode. When querying, return the HTML encoding of the element and all child nodes within the node.

1
readonly String XmlElement.outerHTML;

className

String, query and set the class attribute of the element, only valid in html mode

1
String XmlElement.className;

attributes

XmlNamedNodeMap, returns a NamedNodeMap containing the attributes of the selected node. If the selected node is not an element, this property returns NULL.

1
readonly XmlNamedNodeMap XmlElement.attributes;

nodeType

Integer, returns the node type of the node

1
readonly Integer XmlElement.nodeType;

The nodeType of different objects will return different values:


nodeName

String, returns the name of the node, according to its type

1
readonly String XmlElement.nodeName;

The nodeName of different objects will return different values:


nodeValue

String, returns the name of the node, according to its type

1
String XmlElement.nodeValue;

The nodeName of different objects will return different values:


ownerDocument

XmlDocument, returns the root element of the node (XmlDocumentobject)

1
readonly XmlDocument XmlElement.ownerDocument;

parentNode

XmlNode, can return the parent node of a node

1
readonly XmlNode XmlElement.parentNode;

childNodes

XmlNodeList, returns the node list of the child nodes of the specified node

1
readonly XmlNodeList XmlElement.childNodes;

children

XmlNodeList, returns the node list of the child element nodes of the specified node.

1
readonly XmlNodeList XmlElement.children;

firstChild

XmlNode, returns the first child node of the node

1
readonly XmlNode XmlElement.firstChild;

lastChild

XmlNode, returns the last child node of the node

1
readonly XmlNode XmlElement.lastChild;

previousSibling

XmlNode, returns the node immediately preceding a node (at the same tree level). If there is no such node, then this property returns null.

1
readonly XmlNode XmlElement.previousSibling;

nextSibling

XmlNode, returns the node immediately following an element (in the same tree level). If there is no such node, the attribute returns null.

1
readonly XmlNode XmlElement.nextSibling;

firstElementChild

XmlNode, returns the first child element node of the node

1
readonly XmlNode XmlElement.firstElementChild;

lastElementChild

XmlNode, returns the last child element node of the node

1
readonly XmlNode XmlElement.lastElementChild;

previousElementSibling

XmlNode, returns the element node immediately preceding a node (at the same tree level). If there is no such node, then this property returns null.

1
readonly XmlNode XmlElement.previousElementSibling;

nextElementSibling

XmlNode, returns the element node immediately following an element (in the same tree level). If there is no such node, the attribute returns null.

1
readonly XmlNode XmlElement.nextElementSibling;

textContent

String, queries and sets the text of the selected element. When querying, returns the values ​​of all text nodes within the element node; when setting, deletes all child nodes and replaces them with a single text node.

1
String XmlElement.textContent;

member function

getAttribute

Query the value of an attribute by name

1
String XmlElement.getAttribute(String name);

Call parameters:

  • name: String, specifies the attribute name of the query

Return results:

  • String, returns the value of the attribute

getAttributeNS

Get attribute value by namespace URI and name

1 2
String XmlElement.getAttributeNS(String namespaceURI, String localName);

Call parameters:

  • namespaceURI: String, specifying the namespace URI of the query
  • localName: String, specifies the attribute name of the query

Return results:

  • String, returns the value of the attribute

setAttribute

Create or change a new property

1 2
XmlElement.setAttribute(String name, String value);

Call parameters:

  • name: String, specifies the attribute name to be set
  • value: String, specifies the attribute value to be set

This method sets the specified property to the specified value. If a property with the specified name does not exist, this method creates a new property


setAttributeNS

Create or alter namespaced properties

1 2 3
XmlElement.setAttributeNS(String namespaceURI, String qualifiedName, String value);

Call parameters:

  • namespaceURI: String, specifies the namespace URI to be set
  • qualifiedName: String, specifies the attribute name to be set
  • value: String, specifies 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 a namespace URI and a qualified name consisting of a namespace prefix, a colon, and a local name in the namespace. In addition to changing the value of an attribute, you can also use this method to change the namespace prefix of the attribute.


removeAttribute

Remove specified attribute by name

1
XmlElement.removeAttribute(String name);

Call parameters:

  • name: String, specifies the attribute name to be deleted

removeAttributeNS

Remove specified properties by namespace and name

1 2
XmlElement.removeAttributeNS(String namespaceURI, String localName);

Call parameters:

  • namespaceURI: String, specifies the namespace URI to be deleted
  • localName: String, specifies the attribute name to be deleted

hasAttribute

Query whether the current node has an attribute with the specified name

1
Boolean XmlElement.hasAttribute(String name);

Call parameters:

  • name: String, specifies the attribute name of the query

Return results:

  • Boolean, if the current element node has the specified attribute, returns true, otherwise returns false

hasAttributeNS

Query whether the current node has attributes with the specified namespace and name

1 2
Boolean XmlElement.hasAttributeNS(String namespaceURI, String localName);

Call parameters:

  • namespaceURI: String, specifies the namespace URI to be queried
  • localName: String, specifies the attribute name of the query

Return results:

  • Boolean, if the current element node has the specified attribute, returns true, otherwise returns false

getElementsByTagName

Returns all elements with the specified nameXmlNodeList

1
XmlNodeList XmlElement.getElementsByTagName(String tagName);

Call parameters:

  • tagName: String, the tag name to be retrieved. The value "*" matches all tags

Return results:

  • XmlNodeList, the XmlElement node with the specified tag in the node treeXmlNodeListgather. The order of returned element nodes is the order in which they appear in the source document.

This method will traverse the descendant nodes of the specified element and return an XmlElement node.XmlNodeListObject representing 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.

XmlDocumentThe interface also defines the getElementsByTagName method, which is similar to this method, but traverses the entire document instead of traversing the descendant nodes of an element.


getElementsByTagNameNS

Returns all elements with the specified namespace and nameXmlNodeList

1 2
XmlNodeList XmlElement.getElementsByTagNameNS(String namespaceURI, String localName);

Call parameters:

  • namespaceURI: String, specifies the namespace URI to be queried
  • localName: String, the tag name to be retrieved. The value "*" matches all tags

Return results:

  • XmlNodeList, the XmlElement node with the specified tag in the node treeXmlNodeListgather. 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

1
XmlElement XmlElement.getElementById(String id);

Call parameters:

  • id: String, the id to be retrieved

Return results:

  • XmlElement, the 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. .

XmlDocumentThe interface also defines the getElementsByTagName method, which is similar to this method, but traverses the entire document instead of traversing the descendant nodes of an element.


getElementsByClassName

Returns a node list of all elements with the specified class name

1
XmlNodeList XmlElement.getElementsByClassName(String className);

Call parameters:

  • className: String, the class name to be retrieved

Return results:

  • XmlNodeList, the XmlElement node with the specified class name in the document treeXmlNodeListgather. The order of returned element nodes is the order in which they appear in the source document.

This method will return aXmlNodeListObject (can be processed as a read-only array), which 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.XmlNodeListThe 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

1
Boolean XmlElement.hasChildNodes();

Return results:

  • Boolean, returns true if there are any child nodes, otherwise returns false

normalize

Merge adjacent Text nodes and delete empty Text nodes

1
XmlElement.normalize();

This method will traverse all descendant nodes of the current node and normalize the document by deleting empty Text nodes and merging all adjacent Text nodes. This method is useful for simplifying the structure of the document tree after inserting or deleting nodes.


cloneNode

Creates an exact copy of the specified node

1
XmlNode 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 results:

This method will copy and return a copy of the node on which it was called. If the argument passed to it is true, it will also recursively copy all descendant nodes 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 an Element node is copied, all its properties will be copied.


lookupPrefix

Returns the prefix matching the specified namespace URI on the current node

1
String XmlElement.lookupPrefix(String namespaceURI);

Call parameters:

  • namespaceURI: String, specifies the matching namespace URI

Return results:

  • String, returns the matching prefix, returns null if not matched.

lookupNamespaceURI

Returns the namespace URI matching the specified prefix on the current node

1
String XmlElement.lookupNamespaceURI(String prefix);

Call parameters:

  • prefix: String, specifies the matching prefix

Return results:

  • String, returns the matching namespace URI, returns null if not matched.

insertBefore

Insert a new child node before an existing child node

1 2
XmlNode XmlElement.insertBefore(XmlNode newChild, XmlNode refChild);

Call parameters:

  • newChild:XmlNode, insert new node
  • refChild:XmlNode, insert a new node before this node

Return results:

  • XmlNode, returns the new child node

If newChild already exists in the document tree, it will be removed from the document tree and reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. That is, the ownerDocument attribute of newChild must be the same as the ownerDocument attribute of the current node.


insertAfter

Insert a new child node after an existing child node

1 2
XmlNode XmlElement.insertAfter(XmlNode newChild, XmlNode refChild);

Call parameters:

  • newChild:XmlNode, insert new node
  • refChild:XmlNode, insert a new node after this node

Return results:

  • XmlNode, returns the new child node

If newChild already exists in the document tree, it will be removed from the document tree and reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. That is, the ownerDocument attribute of newChild must be the same as the ownerDocument attribute of the current node.


appendChild

Adds a new child node to the end of a node's child node list

1
XmlNode XmlElement.appendChild(XmlNode newChild);

Call parameters:

  • newChild:XmlNode, specify the added node

Return results:

  • XmlNode, returns this new child node

If newChild already exists in the document tree, it will be removed from the document tree and reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. That is, the ownerDocument attribute of newChild must be the same as the ownerDocument attribute of the current node.


replaceChild

Replace a child node with another

1 2
XmlNode XmlElement.replaceChild(XmlNode newChild, XmlNode oldChild);

Call parameters:

  • newChild:XmlNode, specify the new node
  • oldChild:XmlNode, specifies the node to be replaced

Return results:

  • 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 removed from the document tree and reinserted in its new position. Nodes from one document (or nodes created by one document) cannot be inserted into another document. That is, the ownerDocument attribute of newChild must be the same as the ownerDocument attribute of the current node.


removeChild

Remove a node from the list of child nodes

1
XmlNode XmlElement.removeChild(XmlNode oldChild);

Call parameters:

  • oldChild:XmlNode, specifies the node to be deleted

Return results:

  • 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, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String XmlElement.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

1
Value XmlElement.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable