vbscript xml problem
I have this vbscript that calls a web service written in .net 2010. I'm getting an error at the last line. Can't figure it out. This is the webservice: http://www.kollelbaaleibatim.com/services/getinfo.a开发者_JAVA百科smx/GetFronpageInfo
Dim xmlDOC
Dim bOK
Dim J
Dim HTTP
Dim ImagePathLeftCar, ImagePathRightCar
Dim CarIDLeft, CarIDRight
Dim ShortTitleLeftCar, ShortTitleRightCar
Dim DescriptionLeftCar, DescriptionRightCar
Dim PriceLeftCar, PriceRightCar
Set HTTP = CreateObject("MSXML2.XMLHTTP")
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.Async=False
HTTP.Open "GET","http://www.kollelbaaleibatim.com/services/getinfo.asmx/GetFronpageInfo", false
HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTP.Send()
dim xmldoc2
set xmldoc2 = Server.CreateObject("Microsoft.XMLDOM")
xmldoc2.async = False
bOK = xmldoc2.load(HTTP.responseXML)
if Not bOK then
response.write( "Error loading XML from HTTP")
end if
response.write( xmldoc2.documentElement.xml)'Prints a good looking xml
ShortTitleLeftCar = xmldoc2.documentElement.selectSingleNode("LeftCarShortTitle").text 'ERROR HERE
This isn't a VBScript issue, it is an xpath issue. xmldoc2.documentElement.selectSingleNode("LeftCarShortTitle")
will try find the "LeftCarShortTitle" element as a child of the root....which in your case won't work as there are various levels before this i.e. <string><Root><FrontpageData>
.
Update your xpath to be:
//LeftCarShortTitle
This will traverse the descendants of the document and should find the node your looking for.
精彩评论