views:

66

answers:

1

Hello Friends, 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.asmx/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
A: 

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.

James
Although as a general rule // should be avoided, if the XML structure is known an explicit path is more robust.
AnthonyWJones
@Anthony, yeah I agree. However, for the sake of solving the problem I felt the above would suffice considering the XML response isn't very large.
James