一部の Web サービス応答 XML からノードを選択しようとしていますが、役に立ちません。何らかの理由でルート ノード ("xmldata") を選択できますが、さらに深く掘り下げようとすると ("xmldata/customers")、すべてが空で返されます。以下は、Web サービスによって返される XML のサンプルです。
<xmldata>
<customers>
<customerid>22506</customerid>
<firstname>Jim</firstname>
<issuperadmin>N</issuperadmin>
<lastname>Jones</lastname>
</customers>
</xmldata>
ここに、customerid、firstname、および lastname を選択しようとしているコードを示します。
' Send the Xml
oXMLHttp.send Xml_to_Send
' Validate the Xml
dim xmlDoc
set xmlDoc = Server.CreateObject("Msxml2.DOMDocument")
xmlDoc.load (oXMLHttp.ResponseXML.text)
if(len(xmlDoc.text) = 0) then
Xml_Returned = "<B>ERROR in Response xml:<BR>ERROR DETAILS:</B><BR><HR><BR>"
end if
dim nodeList
Set nodeList = xmlDoc.SelectNodes("xmldata/customers")
For Each itemAttrib In nodeList
dim custID, custLname, custFname
custID =itemAttrib.selectSingleNode("customerid").text
custLname =itemAttrib.selectSingleNode("lastname").text
custFname =itemAttrib.selectSingleNode("firstname").text
response.write("News Subject: " & custID)
response.write("<br />News Subject: " & custLname)
response.write("<br />News Date: " & custFname)
Next
上記のコードの結果は zilch です! ページには何も書き込まれません。奇妙なことの 1 つは、ルート要素を選択してその長さを次のように取得した場合です。
Set nodeList = xmlDoc.SelectNodes("xmldata")
Response.Write(nodeList.length) '1 is written to page
1の長さを正しく決定します。ただし、次のノードダウンで同じことを試みると、次のようになります。
Set nodeList2 = xmlDoc.SelectNodes("xmldata/customers")
Response.Write(nodeList.length) '0 is written to page
長さ 0 を返します。
これが、これらのノードの値にアクセスしようとした唯一の方法ではないことに注意してください。私は自分が間違っていることを理解できません。誰かが私を助けてくれませんか。乾杯。