XML读取事例程序
data.xml 数据文件
1 <?xml version="1.0" encoding="utf-8" ?>
2 <root>
3 <row ID="1" COMPNAME="DALIAN" POST="063000" TEL="0315-2695" LEVEL="888888888"/>
4 <row ID="2" COMPNAME="TIANJUN" POST="063000" TEL="0315-2695" LEVEL="888888888"/>
5 <row ID="3" COMPNAME="BEIJIN" POST="063000" TEL="0315-2695" LEVEL="888888888"/>
6 </root>
读取程序一:遍历全部节点
<%
Dim xml,objNode,objAtr,nCntChd,nCntAtr
Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.Load(Server.MapPath("data.xml"))
Set objNode=xml.documentElement
nCntChd=objNode.ChildNodes.length-1
For i=0 to nCntChd
Set objAtr=objNode.ChildNodes.item(i)
nCntAtr=objAtr.Attributes.length-1
For j=0 To nCntAtr
response.write objAtr.Attributes.item(j).Text&"<br>"
Next
Response.Write "<br>"
Next
Response.Write "<br>"
Set objAtr=Nothing
Set objNode=Nothing
Set xml=Nothing
%>
读取程序二:获取“COMPNAME”节点的内容
<%
Dim xml,objNode,objAtr,nCntChd,nCntAtr
Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.Load(Server.MapPath("data.xml"))
Set objNode=xml.documentElement
nCntChd=objNode.ChildNodes.length-1
For i=0 to nCntChd
Set objAtr=objNode.ChildNodes.item(i)
nCntAtr=objAtr.Attributes.length-1
response.write objAtr.Attributes.item(i).Text&"<br>"
Next
Response.Write "<br>"
Set objAtr=Nothing
Set objNode=Nothing
Set xml=Nothing
%>
我来自:向东博客