ASP Operation XML

Source: Internet
Author: User

' 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 ("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
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
' 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
' Method 2
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
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

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: 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.