ASP uses xmldom to operate XML files on the server.

Source: Internet
Author: User
For small data volumes, XML files have many advantages over access in retrieval and update.

I have tested whether to use a database and store all the Website member information, product data information, transaction information, and website customization information in three XML files. The running result is normal, it seems that it is much faster than the database, but it is not tested and cannot be determined.

The following describes how to create, query, modify, and perform XML operations.

'Create a DOM object
Set objdom = server. Createobject ("Microsoft. xmldom ")

'Retrieve XML data
'Method 1: Get the XML data of the XML file
Objdom. Load ("C: \ test. xml ")
'Method 2: Get the data of the XML data string
Objdom. loadxml ("<people> <man name =" SD "/> </People> ")

'Create a Node object
Set newnode = objdom. createelement ("people ")
'Return value to this node
Newnode. Text = "person"
'Add attributes to this node
Set newattride = objdom. createnode ("attribute", "name ","")
Newattri. Text = "James"
Newnode. setattributenode newattribute
'Add a subnode to this node
Set newnodechild = objdom. createelement ("Address ")
Newnode. appendchild newnodechild
'Save this Node object
Objdom. appendchild newnode
Objdom. Save ("C: \ test. xml ")

'Look up a Node object
Set objtofind=objdom.doc umentelement. selectsinglenode ("// people/Man ")
'Get the node name, node value, attribute value, and all XML of the Node object.
Nodename = objtofind. nodename
Nodevalue = objtofind. Text
Objtofind. getattributenode ("name"). nodevalue

'Retrieve an attribute Node object
Set objattrtofind=objdom.doc umentelement. selectsinglenode ("// people/Man"). getattributenode ("name ")
'Retrieve the attribute name and attribute value of this node.
Nodeattrname = objattrtofind. nodename
Nodeattrvalue = objattrtofind. nodevalue

'Delete a Node object
Set objnode1_objdom.doc umentelement. selectsinglenode ("// people/Man") 'node to be deleted
Set objparentnode1_objdom.doc umentelement. selectsinglenode ("// people") 'parent node of the node to be deleted
Objparentnode. removechild objnode

'Retrieve the byte point set of a node
Set objnodesnodes objdom.doc umentelement. selectsinglenode ("// people/Man"). childnodes
Traverse this set
Method 1
For each element in objnodes
Response. Write element. nodename byte name
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

'Retrieve the attribute set of a node
Set objnodesincluobjdom.doc umentelement. selectsinglenode ("// people/Man"). getattributenode ("name"). Attributes
Traverse this set
For each element in objnodes
Response. Write element. nodename attribute name
Response. Write element. nodevalue Attribute Value
Next

If You Can skillfully use xmldom objects to operate XML files, you can enjoy XMLHTTP objects to implement many functions under ASP.

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.