Recommended: The main methods and implementations of ASP operating XML files ASP uses XMLDom to operate XML files on the server side. For small data volumes, XML files have many advantages in retrieval and updates in ACCESS. I have tested that without using a database, I store all the member information of the website, product data information, transaction information, and website customization information in three xml files. The operation result is very normal, and it feels more than data
Many friends will occasionally encounter the need to control the xml database asp , so now I will sort out the relevant code for controlling the xml database asp.
There are six items in total, the code is as follows:
asp control xml database code 1--Create an XML database data.xm
<?xml version=1.0?>
<records>
<record>
<name>caca</name>
<qq>1542222225</qq>
<email>[email protected]</email>
</record>
<records>
asp control xml database code 2--Create object CreateObject
Create data.xml object first
set xmldoc=server.createobjcet(microsoft.xmldom)
xmldoc.load(server.mappath(data.xml)
asp control xml database code 3--Select Node SelectNode
Which Node do you want to operate? Do you have to locate this node? Let’s first look at how many Nodes there are in this data.xml?
Use a recursive function to do it:
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>) Webjx.Com
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, you can see that this data.xml has 10 Nodes
These Nodes can be positioned very simply:
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 simple? There is another method, such as positioning <name>
xmldoc.selectsinglenode(//name)
Asp control xml database code 4-assign a value to the node (modify the node's value)
After learning to locate nodes and use their attributes, you can modify or assign values.
For example, change the value of <name> caca to wawa
xmldoc.selectsinglenode(//name).text=wawa Webjx.Com
xmldoc.save(server.mappath(data.xml))
Get it done!
NO.5--CreatenewNode
Use createelement or createnode(,,)
For example: Create a new <age> under record, and it takes only one sentence to do it:
xmldoc.selectsinglenode(//record).appendchild(xmldoc.createelement(<age>))
Assign a value to <age>
xmldoc.selectsinglenode(//age).text=20
xmldoc.save(server.mappath(data.xml))
Get it done!
asp control xml database code 6--DeleteNode DeleteNode
You must clarify the parent node of the node you want to delete and the characteristics of the node
For example: Delete the <qq> node
xmldoc.selectsinglenode(//record).removechild(xmldoc.selectsinglenode(//qq))
For example: delete the <name>=caca's <record>
xmldoc.selectsinglenode(//records).removechild(xmldoc.selectsinglenode(//record[name='caca']))
xmldoc.save(server.mappath(data.xml)) Webjx.Com
Get it done!
If you master these 6 codes for controlling the xml database and use asp to control the xml database, it will be much easier.
Share: ASP adds, deletes, modifys, and views text in XML documents % '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------