如何使用经典ASP读取XML根节点中的属性?

如何使用经典ASP读取XML根节点中的属性?

问题描述:

我正在尝试使用经典ASP读取此XML的根节点中的“ts”属性,但似乎无法获得正确的语法。我能够读取下面各个节点和嵌套节点中的属性,但我需要从根节点获取信息。如何使用经典ASP读取XML根节点中的属性?

任何人都可以提出解决方案吗?

XML代码片段:

<?xml version="1.0" encoding="utf-8"?> 
<results ts="2012-04-24 17:10:45" nm="Test project" fin="0" bal="131494" vot="131494" tab="614" cltab="172" pol="1737" clpol="72" stpol="1735"> 
    <choices> 
     <choice id="1" tot="1" vot="211" e="1" /> 
     <choice id="2" tot="1" vot="196" e="-1" /> 
    </choices> 
    <area id="1" bal="131494" vot="131494" bal2="131494" vot2="131494" tab="614" cltab="172" pol="1737" clpol="72" stpol="1735"> 
     <tab> 
      <cg cgId="1" tot="132" clos="131" /> 
      <cg cgId="2" tot="23" clos="23" /> 
      <cg cgId="3" tot="459" clos="18" /> 
     </tab> 
    </area> 
    </areas> 
</results> 

ASP代码片段阅读是工作的罚款典型的节点...

Dim objResultXML 
Set objResultXML = Server.CreateObject("Microsoft.XMLDOM") 
objResultXML.async = False 
objResultXML.Load (Server.MapPath("FileToParse.xml")) 

ReDim ResultArray(3,0) 
Set NodeList = objResultXML.documentElement.selectNodes("choices/choice") 
For Each Node In NodeList 
    If CStr(ResultArray(0,0))<>"" Then ''< Balance signs 
     ReDim Preserve ResultArray(3,UBound(ResultArray,2)+1) 
    End if 
    ResultArray(0,UBound(ResultArray,2)) =CLng(Node.getAttribute("id")) 
    ResultArray(1,UBound(ResultArray,2)) =CLng(Node.getAttribute("tot")) 
    ResultArray(2,UBound(ResultArray,2)) =CLng(Node.getAttribute("vot")) 
    ResultArray(3,UBound(ResultArray,2)) =CStr(Node.getAttribute("e")) 

Next 
Set NodeList=Nothing 

.documentElementresults元素。

所有你需要的只是:objResultXML.documentElement.getAttribute("ts")

+0

非常感谢! – daveo 2012-04-27 17:31:10