ASP operates XML files on the server side via XMLDOM

Source: Internet
Author: User
For small amounts of data, XML files have many advantages in retrieving updates on access.

I have tested the use of the database, the site's membership information, merchandise data information, transaction information, Web site customization information stored in three XML files, the results of the operation is very normal, feeling more than the database faster, but did not test, can not be determined.

Here are the main ways to create, query, modify, and so on XML operations

' Create a 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")
' To the value of this node
Newnode.text= "Man"
' Add attributes to this node
Set newattribute=objdom.createnode ("attribute", "name", "")
newattribute.text= "John"
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 named Name

' Remove an Attribute node object
Set Objattrtofind=objdom.documentelement.selectsinglenode ("//people/man"). GetAttributeNode ("name")
' Take out the attribute name of this node, 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 set of byte points for a node
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 Roll Call
Response.Write Objnodes.childnodes (i). Text byte point value
Next

Remove 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
-->
Related Article

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.