2

従来の ASP を使用して、この XML の rootnode にある "ts" 属性を読み取ろうとしていますが、適切な構文を取得できないようです。以下のさまざまなノードとネストされたノードの属性を読み取ることができますが、ルートノードからの情報が必要です。

誰でも解決策を提案できますか?

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
4

1 に答える 1

5

.documentElementresults要素です。

必要なのはそれだけです:objResultXML.documentElement.getAttribute("ts")

于 2012-04-25T22:55:25.420 に答える