Xpath with XML from a Web Service
HI,
I have been hacking away pulling data from a webservice and have managed to get the results that I need so I am now at the stage where I want to do something useful with the XML that is returned so I have been playing with Xpath.
As I understand it I can use Xsearch to pull nodes from the XML object rather than have to write the XML out to a file and then search through the file. The problem I am having is that when I use Xsearch it doesn't extract the data that I expect it to. ![]()
Here is the XML that is returned from the web service which I assign to the variable xmlReturned:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetChildLocationsResponse xmlns="http://tempuri.org/VillarentersWebService/villa_search">
<GetChildLocationsResult>
<RequestedParentID>3924</RequestedParentID>
<VRF />
<ChildLocations>
<Location>
<LocationRef>10</LocationRef>
<LocationDescription>Argentina</LocationDescription>
<ParentID>3924</ParentID>
</Location>
<Location>
<LocationRef>30</LocationRef>
<LocationDescription>Brazil</LocationDescription>
<ParentID>3924</ParentID>
</Location>
</ChildLocations>
</GetChildLocationsResult>
</GetChildLocationsResponse>
</soap:Body>
</soap:Envelope>
So when I use :
<cfset locDescription = XmlSearch(xmlReturned, "//LocationDescription") />
<cfdump var="#locDescription#">
I am expecting to see an array with 2 elements, Argentina and Brazil. What I actually get is an empty array. I have tried using a really handy online Xpath checker at http://www.zrinity.com/xml/xpath/index.cfm and I get the same result. I tried a few different searches but each time the array is empty.
Does anyone know why it isn't pulling the requested nodes into the array? Am I missing something very simple here?
