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

时间:2012-04-25 20:29:45

标签: xml asp-classic

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

有人可以建议解决方案吗?

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

1 个答案:

答案 0 :(得分:5)

.documentElementresults元素。

您只需要:objResultXML.documentElement.getAttribute("ts")