' Create DOM Object
Set Objdom=server. CreateObject ("Microsoft.XMLDOM")
' Get XML data
' Method 1 Gets the XML data of the XML file
Objdom.load ("C:\test.xml")
' Method 2 Gets the data of the XML data string
Objdom.loadxml ("<people> <man name=" SD "/> </people>")
' Create a Node object
Set newnode=objdom.createelement ("people")
' Give this Node a value
newnode.text= "People"
' Add attributes to this node
Set newattribute=objdom.createnode ("attribute", "name", "" ")
Newattribute.text= "Zhang San"
Newnode.setattributenode Newattribute
' Add child nodes to this node
Set newnodechild=objdom.createelement ("address")
Newnode.appendchild Newnodechild
' Save this Node object
Objdom.appendchild Newnode
Objdom.save ("C:\test.xml")
' Find a Node object
Set Objtofind=objdom.documentelement.selectsinglenode ("//people/man")
' Take out the node name of this node object, the node value, a property value, and all the XML
Nodename=objtofind.nodename
Nodevalue=objtofind.text Objtofind. GetAttributeNode ("name"). NodeValue
' Property value with Name ' attribute '
' Remove an Attribute node object
Set Objattrtofind=objdom.documentelement.selectsinglenode ("//people/man"). GetAttributeNode ("name")
' Remove this node's attribute name, attribute value
Nodeattrname=objattrtofind.nodename
Nodeattrvalue=objattrtofind.nodevalue
' Delete a Node object
Set Objnode=objdom.documentelement.selectsinglenode ("//people/man")
' The node to be deleted
Set Objparentnode=objdom.documentelement.selectsinglenode ("//people")
' Parent node of the node to be deleted
Objparentnode.removechild Objnode
' Take out a node's set of byte points
Set Objnodes=objdom.documentelement.selectsinglenode ("//people/man"). ChildNodes
' Traverse this collection
' Method 1
For each element in Objnodes
Response.Write element.nodename ' byte Roll Call
Response.Write Element.text ' byte point value
Next
' Method 2
Domlength=objnodes.length
For i = 0 to Domlength-1
Response.Write Objnodes.childnodes (i). NodeName ' byte name
Response.Write Objnodes.childnodes (i). Text ' byte point value next
' Take out a collection of attributes for a node
Set Objnodes=objdom.documentelement.selectsinglenode ("//people/man"). GetAttributeNode ("name"). Attributes
' Traverse this collection
For each element in Objnodes
Response.Write Element.nodename Property Name
Response.Write Element.nodevalue Property Value
Next
A brief description of the objects and methods of the DOM:
The DocumentElement property confirms the root (root) node of the XML file.
selectSingleNode returns the first node that conforms to a style.
The LoadXML method loads a fragment of an XML file or string.
The HasChildNodes method returns a value of TRUE if the specified node has one or more child nodes.
The CreateElement method creates an element of the specified name.
The AppendChild method adds a node as the last child node of the specified node.
The Createcdatasection method creates a CDATA that contains specific data.
ASP Operation XML