XML Document Object Model

Source: Internet
Author: User

 

XML Document Object Model

1)DomdocumentObject: This object describes all the document ing tables. The document ing table contains all the information in the XML document.
Common Methods
Common attributes

2)IxmldomnodeObject: This object describes the nodes in the XML document. This node can be an element, attribute, processing command, text, or other information stored in an XML document.
Common Methods
Common attributes

3)IxmldomnodelistObject: This object describes the set of ixmldomnode objects and can be used to traverse the set. The node set in the ixmldomnodelist object can be used as a numerical value.
Common Methods
Common attributes

4)IxmldomparseerrorObject: This object is used to verify the schema or DTD correctness of the XML document and obtain the error information generated during the verification process.
Common Methods
Common attributes

*Common domdocument object Methods:
A) createelement (Elementname) ---- This method creates an element node named after this parameter with the element name. (You cannot create restricted namespace elements. If you want to create a namespace restricted element, you must use the createnode () method)
Example: Doc. createelement ("product ")

B) createattribute (Attributename) ---- This method creates an attribute node named after this parameter with the property name.
Example: Doc. createattribute ("prodid ")

C) createcomment (Text) ---- This method uses a string as the parameter to create a comment node that contains this string.
Example: Doc. createcomment ("this is an XML document ")

D) createtextnode (Text) ---- This method uses the string as the parameter to create a body node that contains the specified string.
Example: Doc. createtextnode ("Sony workman ")

E) createnode (Type, name, namespace-Uri) ---- This method creates an element node. The "type" parameter can be a string or an integer. The second parameter is a string that represents the name of the node to be created. The third parameter is a string that represents namespace-Uri. If namespace-Uri is a null string, the newly created node does not have a namespace URI.
Example: Doc. createnode ("element", "product ","")
Doc. createnode ("element", "prod: product", "blog.csdn.net/fcrpg2005 ")
Doc. createnode (1, "product ","")

F) getelementsbytagname (Elementname) ---- This method takes the string as the parameter. This string is the element to be searched. Return the ixmldomnodelist object, which contains the set of nodes with the specified element name. You can use these node tokens to browse and manipulate the values stored in the specified element.
Example: Doc. geteelmentsbytagname ("price ")

G) load (Xmldocument) ---- This method takes the string as the parameter. This string is the address of the XML document (HTTP address or local address)
Example: Doc. Load ("http://blog.csdn.net/fcrpg2005/product.xml ")
Doc. Load ("D:/product. xml ")

H) loadxml (String) ---- This method loads the formed XML Code or the entire XML file into the domdocument object.
Example: Doc. loadxml ("<? XML version = 1.0> <Products> <product> <Name> Barbie doll </Name> </product> </Products> ")

I) transformnode (Stylesheet object) ---- This method takes the style table object as the parameter. Add the corresponding style table to the XML document to process the node and return the conversion result.
Example: Doc. transformnode ("product. XSL ")

J) appendchild (Child Node) ---- This method takes the object as the parameter. Add this object as the final sub-node to the XML document. The createnode () or createelement () method can be used to create nodes or elements. However, they do not add new nodes to the document tree structure. Instead, you must use the appendchild () method, insertbefore () method, or the replaceChild () method to add the newly created node.
For example, Doc. appendchild (Root) ---- PS: Root is a node created using the createnode () or createelement () method.

K) Save (Destination) ---- This method takes the object as the parameter. This object can be a domdocument object or a file name. The SAVE () method saves the domdocument object to the specified destination.
Example: Doc. Save ("http://blog.csdn.net/fcrpg2005/product.xml ")

*Common domdocument attributes:
A) async ---- This attribute is used to specify whether asynchronous loading is allowed. The attribute async obtains a Boolean value.
For example, Doc. async = false -- Synchronization

B) childnodes ---- This attribute returns the child node set that belongs to a parent node (that is, the array object of all the child elements of the current element ). The value of this attribute is of the ixmldomnodelist type.
Example: var firstelem = Doc. childnodes. Item (1)

C) documentelement ---- This attribute contains the root element of the XML document represented by the object domdocument.
For example, VAR root = doc.doc umentelement

D) firstchild ---- This attribute returns the first child node of the parent element. This element is read-only.
For example, VAR firstelem = Doc. firstchild

E) lastchild ---- This attribute returns the last child node of the parent element.
For example, VAR lastelem = Doc. lastchild

F) parseerror ---- This attribute returns an object that contains most of the most recent error messages.
For example, VAR error = Doc. parseerror

G) readystate ---- This attribute returns the status of the XML document. It shows whether the document is fully loaded. Four statuses: 0-not initialized, 1-loading, 2-loaded, 3-interacting, and 4-completed
For example, VAR stateinfo = Doc. readstate
If (stateinfo = 4) {// document loading
// Coding
}

H) XML ---- This attribute returns the XML Representation of a node with its subnodes.
Example: Document. Write (Doc. XML)

I) validateonparse ---- This attribute specifies whether the parser verifies its validity when parsing XML documents.
Example: Doc. validateonparse = true

**Common Methods for ixmldomnode objects:
A) appendchild (Newchild) ---- This method adds newchild to the end of the subnode of the node used by this method.

B) insertbefore (Newnode, refnode) ---- This method inserts a new node newnode into an existing node refnode.

C) removechild (Nodename) ---- This method deletes the specified node.

D) replaceChild (Newnode, oldnode) ---- This method replaces the old oldnode with the new node newnode.

E) haschildnodes () ---- if the ixmldomnode object has subnodes, the return value of this method is true ).

F) clonenode (Boolean) ---- If the Boolean parameter is true, this method returns a full clone of the ixmldomnode object. The cloned node contains the same child nodes as the original node.

**Common attributes of ixmldomnode objects:
A) nodename ---- return the node name.

B) nodetype ---- return the node type.

C) nodevalue ---- return the text contained in the node.

D) childnodes ---- return the child node set of the node represented by the ixmldomnode object.

E) firstchild ---- returns the first subnode of the node.

F) lastchild ---- return the last child node of the node.

G) text ---- return the text of ixmldomnode in the ixmldomnode object.

H) XML ---- return the XML code of the ixmldomnode object

***Common Methods for ixmldomnodelist objects:
A) item (Number) ---- This method returns the node at the corresponding position of the specified value.

B) nextnode () ---- This method returns the next node of the node set.

***Common attributes of ixmldomnodelist objects:
Length ---- obtain the number of nodes in the node set.

****Common attributes of ixmldomparseerror objects:
A) errorcode ---- this property contains the error code of the Long Integer type. If the XML document has no error, this attribute returns 0.

B) reason ---- This attribute contains a string that explains the cause of the error.

C) line ---- This attribute stores long integers that represent the number of wrong rows.

D) linepos ---- This attribute stores long integers that represent the location of the wrong row.

E) srctext ---- This attribute contains the line that caused the error.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.