Object built-in object

Object XmlDocument

XmlDocument object represents the entire XML document

The XmlDocument object is the root of a document tree, which provides us with the initial (or topmost) access to the document data. For element nodes, text nodes, comments, processing instructions, etc., all cannot exist outside of XmlDocument. The XmlDocument object also provides methods for creating these objects. XmlNode objects provide an ownerDocument property that associates them with the XmlDocument in which they are created.

Inheritance

Constructor

XmlDocument

Construct an XmlDocument object

1
new XmlDocument(String type = "text/xml");

Call parameters:

  • type : String, specify the type of the document object, the default is "text/ xml ", if you need to process html, you need to specify "text/html"

Member attributes

inputEncoding

String, returns the encoding used for the document (when parsing)

1
readonly String XmlDocument.inputEncoding;

xmlStandalone

Boolean, set or return whether the document is standalone

1
Boolean XmlDocument.xmlStandalone;

xmlVersion

String, set or return the XML version of the document

1
String XmlDocument.xmlVersion;

doctype

XmlDocumentType , returns the document type declaration related to the document (Document Type Declaration)

1
readonly XmlDocumentType XmlDocument.doctype;

For XML documents without DTD, null is returned. This attribute provides direct access to the XmlDocumentType object (a child node of XmlDocument).


documentElement

XmlElement , returns the root node of the document

1
readonly XmlElement XmlDocument.documentElement;

XmlElement , returns the head node of the HTML document, only valid in html mode

1
readonly XmlElement XmlDocument.head;

title

String, returns the content of the title node of the HTML document, only valid in html mode

1
readonly String XmlDocument.title;

body

XmlElement , returns the body node of the HTML document, only valid in html mode

1
readonly XmlElement XmlDocument.body;

nodeType

Integer, returns the node type of the node

1
readonly Integer XmlDocument.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 XmlDocument.nodeName;

The nodeName of different objects will return different values:


nodeValue

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

1
String XmlDocument.nodeValue;

The nodeName of different objects will return different values:


ownerDocument

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

1
readonly XmlDocument XmlDocument.ownerDocument;

parentNode

XmlNode , can return the parent node of a node

1
readonly XmlNode XmlDocument.parentNode;

childNodes

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

1
readonly XmlNodeList XmlDocument.childNodes;

firstChild

XmlNode , returns the first child node of the node

1
readonly XmlNode XmlDocument.firstChild;

lastChild

XmlNode , returns the last child node of the node

1
readonly XmlNode XmlDocument.lastChild;

previousSibling

XmlNode , returns the node immediately before a node (at the same tree level), if there is no such node, then this attribute returns null

1
readonly XmlNode XmlDocument.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

1
readonly XmlNode XmlDocument.nextSibling;

Member function

load

Compose the document by parsing an XML/HTML string, does not support multilingual

1
XmlDocument.load(String source);

Call parameters:

  • source : String, the XML/HTML text to be parsed, depending on the type of document when it was created

Compose the document by parsing a binary XML/HTML string and automatically convert it according to the language

1
XmlDocument.load(Buffer source);

Call parameters:

  • source : Buffer , the XML/HTML text to be parsed, depends on the type of document when it was created

getElementsByTagName

Returns a node list of all elements with the specified name

1
XmlNodeList XmlDocument.getElementsByTagName(String tagName);

Call parameters:

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

Return result:

  • XmlNodeList , a collection of XmlNodeList of XmlElement nodes with specified tags in the document tree. The order of returned element nodes is the order in which they appear in the source document.

This method will return an XmlNodeList object (which can be processed as a read-only array), which stores all XmlElement nodes in the document with the specified tag name. The order in which they are stored is the order in which they appear in the source document. XmlNodeList object is "live", that is, if an element with a specified tag name is added or deleted in the document, its content will automatically be updated as necessary.


getElementsByTagNameNS

Returns a list of nodes with all elements of the specified namespace and name

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

Call parameters:

  • namespaceURI : String, specifies the namespace URI to retrieve. The value "*" can match all tags
  • localName : String, the label name to be retrieved. The value "*" matches all tags

Return result:

  • XmlNodeList , a collection of XmlNodeList of XmlElement nodes with specified tags in the document tree. 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 it retrieves elements based on the namespace and name.


getElementById

Returns the element with the specified id attribute

1
XmlElement XmlDocument.getElementById(String id);

Call parameters:

  • id : String, id to be retrieved

Return result:

This method will traverse the descendant nodes of the document and return an XmlElement node object representing the first document element with the specified id attribute. .


getElementsByClassName

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

1
XmlNodeList XmlDocument.getElementsByClassName(String className);

Call parameters:

  • className : String, the name of the class to be retrieved

Return result:

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

This method will return an XmlNodeList object (which 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. XmlNodeList object is "live", that is, if an element with a specified tag name is added or deleted in the document, its content will automatically be updated as necessary.


createElement

Create element node

1
XmlElement XmlDocument.createElement(String tagName);

Call parameters:

  • tagName : String, specifies the specified name of the element node

Return result:


createElementNS

Create element node with specified namespace

1 2
XmlElement XmlDocument.createElementNS(String namespaceURI, String qualifiedName);

Call parameters:

  • namespaceURI : String, specifies the namespace URI of the element node
  • qualifiedName : String, the specified name of the specified element node

Return result:


createTextNode

Create text node

1
XmlText XmlDocument.createTextNode(String data);

Call parameters:

  • data : String, specify the text of this node

Return result:

  • XmlText , returns the newly created XmlText node, which represents the specified data string

createComment

Create comment node

1
XmlComment XmlDocument.createComment(String data);

Call parameters:

  • data : String, specify the comment text of this node

Return result:


createCDATASection

Create XmlCDATASection node

1
XmlCDATASection XmlDocument.createCDATASection(String data);

Call parameters:

  • data : String, specify this node to specify CDATA data

Return result:


createProcessingInstruction

Create XmlProcessingInstruction node

1 2
XmlProcessingInstruction XmlDocument.createProcessingInstruction(String target, String data);

Call parameters:

  • target : String, specify the target of the processing instruction
  • data : String, specify the content text of the processing instruction

Return result:


hasChildNodes

Query whether there are child nodes

1
Boolean XmlDocument.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

1
XmlDocument.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

1
XmlNode XmlDocument.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:

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

1
String XmlDocument.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

1
String XmlDocument.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 2
XmlNode XmlDocument.insertBefore(XmlNode newChild, XmlNode refChild);

Call parameters:

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

Return result:

  • XmlNode , returns 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 2
XmlNode XmlDocument.insertAfter(XmlNode newChild, XmlNode refChild);

Call parameters:

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

Return result:

  • XmlNode , returns 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

1
XmlNode XmlDocument.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 2
XmlNode XmlDocument.replaceChild(XmlNode newChild, XmlNode oldChild);

Call parameters:

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

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

1
XmlNode XmlDocument.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

1
String XmlDocument.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

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

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable