Save the following two pieces of code separately, One save for readxml.asp another save as Test.xml, placed under the same directory, debugger can, in the program I have explained, read the code can be made into a readxml function, by using the input parameters to read XML different data records of different values. This program is adapted from the internet, what is the discrepancy please forgive me.
Copy Code code as follows:
<%
Dim Xml,objnode,objatr,ncntchd,ncntatr
Set xml=server.createobject ("Microsoft.XMLDOM")
Xml. Async=false
Xml. Load (Server.MapPath ("Test.xml"))
Set objnode=xml.documentelement
Ncntchd=objnode.childnodes.length-1
' This defines the value that the ASP reads from the XML file, passing this value to determine which data to read
For I=0 to Ncntchd
Set Objatr=objnode.childnodes.item (i)
Ncntatr=objatr.attributes.length-1
' All the entries in a record, starting with the 0 record.
' http://www.knowsky.com/
For J=0 to Ncntatr
Response.Write ObjAtr.Attributes.item (j). text& "<br>"
Next
Response.Write "<br>"
Next
Set objatr=nothing
Set objnode=nothing
Set xml=nothing
%>
XML file
Copy Code code as follows:
The following is the program code:
<?xml version= "1.0" encoding= "Utf-8"?>
<root>
<row id= "1" compname= "Bridge Porch" addr= "Guangdong province Guangzhou Yuexiu District Beijing Road" Zip code = "510000" tel= "8620-8333" prodserv= "business face" economic industry = "Congee Noodle shop" province = "Guangdong province" city = " Guangzhou "area =" Yuexiu District "visit=" 0 "priority =" 9999999999 "zhuangtai=" latest "/>
<row id= "2" compname= "Zhou Chai" addr= "Guangdong province Guangzhou" Zip code = "510000" tel= "8620-8330" prodserv= "Operating fast food" economic industry = "fast food" province = "Guangdong province" city = "Guangzhou" area = "Yuexiu District" visit= "0" priority = "9999999999" zhuangtai= "newest"/>
<row id= "3" compname= "coriander Hall" addr= "Guangzhou Yuexiu District, Guangdong Province" Zip code = "510000" tel= "8620-837" prodserv= "operating Hunan" economic industry = "Hunan" province = "Guangdong province" city = "Guangzhou" area = "Yuexiu District" visit= "0" priority = "9999999999" zhuangtai= "newest"/>
</root>
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 the style.
The Loadxml method loads a fragment of an XML file or string.
HasChildNodes method if the specified node has one or more child nodes, the return value is true.
The CreateElement method creates an element with the specified name.
The AppendChild method plus a node is treated as the last child node of the specified node.
The Createcdatasection method creates a CDATA that contains specific data.