XML Data Summary of ASP operations

Source: Internet
Author: User

No.1 -- create an XML database data. xml



caca
154222225
root@3ney.com


No. 2 -- create object Createobject
create data. XML Object first
set xmldoc = server. createobjcet ("Microsoft. xmldom ")
xmldoc. load (server. mappath ("data. XML ")

No. 3 -- selectnode
Which node do you want to operate? Do you have to locate this node? check whether there are several nodes in this data. xml file first ??
Use a recursive function:
Getnodes (xmldoc)

Sub getnodes (node)
Dim I
Response. write ("<br> <B> nodename: </B>" & node. nodename & "<br> <B> nodetypestring: </B>" & node. nodetypestring & "<br> <B> nodevalue: </B>" & node. nodevalue & "<br> <B> text: </B>" & node. text & "<br> <B> node. childnodes. length: </B> "& node. childnodes. length & "<p> ")

If node. childnodes. Length <> 0 then
For I = 0 to node. childnodes. Length-1
Getnodes (node. childnodes (I ))
Next
End if
End sub
After using this function, we can see that this data. XML has 10 nodes.
These nodes can be easily located:
Xmldoc
Xmldoc. childnodes (0)
Xmldoc. childnodes (1)
Xmldoc. childnodes (1). childnodes (0)
Xmldoc. childnodes (1). childnodes (0). childnodes (0)
Xmldoc. childnodes (1). childnodes (0). childnodes (0). Text
Xmldoc. childnodes (1). childnodes (0). childnodes (1)
Xmldoc. childnodes (1). childnodes (0). childnodes (1). Text
Xmldoc. childnodes (1). childnodes (0). childnodes (2)
Xmldoc. childnodes (1). childnodes (0). childnodes (2). Text
Is positioning very easy? There is another method, such as positioning <Name>
Xmldoc. selectsinglenode ("// name ")
Also:
Xmldoc. getelementsbytagname ("name"). Item (0)

No. 4 -- assign a value to a node (modify the value of a node)
After learning to locate a node and use its attributes, you can modify or assign values.
For example, change the value of <Name> caca to Wawa.
Xmldoc. selectsinglenode ("// name"). Text = "Wawa"
Xmldoc. Save (server. mappath ("data. xml "))
Done!
No. 5 -- create a new node createnewnode
Use createelement or createnode ("","","")
For example, to create a new <age> under record, you only need to do this in one sentence:
Xmldoc. selectsinglenode ("// record"). appendchild (xmldoc. createelement ("<age> "))
Assign a value to <age>
Xmldoc. selectsinglenode ("// age"). Text = "20"
Xmldoc. Save (server. mappath ("data. xml "))
Done!
No. 6 -- delete a node deletenode
You must specify the parent node of the node you want to delete and its features.
For example, deleting a <QQ> node
Xmldoc. selectsinglenode ("// record"). removechild (xmldoc. selectsinglenode ("// QQ "))
For example, delete the <Name> = caca <record>
Xmldoc. selectsinglenode ("// records"). removechild (xmldoc. selectsinglenode ("// record [name = 'caca'])
Xmldoc. Save (server. mappath ("data. xml "))
Done!
Only these six codes can be used to control the XML database with ASP, which is almost the same...

Here is an example of a message book.
Download

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.