Save the following two pieces of code, one is saved as readxml.asp and the other is saved as test.xml, placed in the same directory, and debug the program. I have explained it in the program. Reading the code can be made into a readxml function, and read different values of different data records of xml by using the input parameters. The adaptation of this program comes from the Internet. Please forgive me for any differences.
The code copy is as follows:
<%
dimxml,objNode,objAtr,nCntChd,nCntAtr
Setxml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.Load(Server.MapPath("test.xml"))
SetobjNode=xml.documentElement
nCntChd=objNode.ChildNodes.length-1
'This can define which value of the asp reads the xml file, and determine the read data by passing this value
fori=0tonCntChd
setobjAtr=objNode.ChildNodes.item(i)
nCntAttr=objAttr.Attributes.length-1
'Walking through all the records in a record, the records start from 0
'http://www.knowsky.com/
forj=0tonCntAtr
response.writeobjAttr.Attributes.item(j).Text&"<br>"
next
response.write"<br>"
next
SetobjAtr=Nothing
SetobjNode=Nothing
Setxml=Nothing
%>
xml file
The code copy is as follows:
The following is the program code:
<?xmlversion="1.0" encoding="utf-8"?>
<root>
<rowID="1"COMPNAME="Jiuqiaoxuan"ADDR="Beijing Road, Yuexiu District, Guangzhou City, Guangdong Province" Zip Code="510000"TEL="8620-8333"PRODSERV="Business Noodle" Economic Industry="Porridge Noodle Shop" Province="Guangdong Province" City="Guangzhou City" Area="Yuexiu District" visit="0" Priority="9999999999"zhuangtai="Latest"/>
<rowID="2"COMPNAME="Zhou Zai"ADDR="Guangzhou City, Guangdong Province" Zip Code="510000"TEL="8620-8330"PRODSERV="Business of fast food" Economic industry="Fast food" Province="Guangdong Province" City="Guangzhou City" Area="Yuexiu District" visit="0" Priority="9999999999"zhuangtai="Latest"/>
<rowID="3"COMPNAME="Cornaise Restaurant"ADDR="Yuexiu District, Guangzhou City, Guangdong Province" Zip Code="510000"TEL="8620-837"PRODSERV="Business of Hunan cuisine" Economic industry="Xiang cuisine" Province="Guangdong Province" City="Guangzhou City" Area="Yuexiu District" visit="0" Priority="9999999999"zhuangtai="Latest"/>
</root>
A brief description of DOM objects and methods:
The documentElement property confirms the root (Root) node of the XML file.
selectSingleNode Returns the first node that matches the style.
The loadXML method loads an XML file or fragment of a string.
haschildnodes method If the specified node has one or more child nodes, the returned value is true.