일부 웹 서비스 응답 XML에서 노드를 선택하려고합니다. 어떤 이유로 나는 루트 노드 ("xmldata")를 선택할 수 있지만 더 깊이 드릴을 시도하면 ("xmldata/customers") 모든 것이 비어있게됩니다! 아래는 웹 서비스가 반환하는 XML의 샘플입니다.VBScript XML 노드를 선택할 수 없습니다.
<xmldata>
<customers>
<customerid>22506</customerid>
<firstname>Jim</firstname>
<issuperadmin>N</issuperadmin>
<lastname>Jones</lastname>
</customers>
</xmldata>
여기에 고객 ID, 이름 및 성을 선택하려고 시도하는 코드가 있습니다.
' 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! 아무 것도 페이지에 쓰여지지 않습니다. 하나의 이상한 것은 내가 루트 요소를 선택하고 길이를 다음과 같이 얻는 것입니다.
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을 반환합니다. 이유는 무엇입니까?
이 노드의 값에 액세스하려고 시도한 유일한 방법은 아닙니다. 나는 단지 내가 잘못하고있는 것을 해결할 수 없다. 누군가 나를 도울 수 있었습니까? 건배.
안녕하세요 Ekkerhard, 답장을 보내 주셔서 감사합니다. 나는 당신이 제안한 것을 시도해 보았고 xmldata 노드보다 더 깊은 것을 선택하려고 할 때 여전히 같은 문제를 겪고있다. – urbanMethod
연장 응답에 대한 환호. 내 문제는 대소 문자를 구분 (나는 세부 사항을 게시했습니다) 관련되었다. 나는 다음 번에 XML 문제에 관해 게시 한 콘솔 스크립트에 균열이 생길 것입니다. – urbanMethod