<!-- 以下内容由sohu社区为您保存 -->
test.xml如下
<?xml version= "1.0 " encoding= "gb2312 "?>
<config>
<province id= "1 " name= "beijng " code= " ">
<city> beijing </city>
</province>
<province id= "2 " name= "liaoning " code= " ">
<city> shenyang </city>
<city> dalian </city>
<city> anshan </city>
</province>
</config>
这样的xml用asp改怎么读取并输出,我在网上搜过一些代码,看的不太明白.请大侠们指点,最好有注释.感谢
------解决方案--------------------
Dim oDoc, oNode
Dim i
Set oDoc = CreateObject( "Msxml2.DOMDocument ")
With oDoc
.Load "c:\text.xml "
If .parseError.errorCode = 0 Then
'取 <province id= "1 " name= "beijng " code= " ">
Set oNode = .documentElement.selectSingleNode( "/config/province[@name= 'beijing '] ")
Response.Write oNode.getAttribute( "id ")
'取所有的city
Set oNode = .documentElement.selectNodes( "//city ")
For i = 0 To oNode.length-1
Response.Write oNode.Item(i).text
Next
End If
Set oNode = Nothing
End With
Set oDoc = Nothing
------解决方案--------------------
我遇到同样的问题,友情UP
------解决方案--------------------
不用With的话就把.开头的成员都改成oDoc.,比如
.documentElement 写成 oDoc.documentElement
没有输出的话说明加载时出错了,c:\text.xml要改成你的 xml文件的路径,并且xml文件本身要正确.