troubleshooting Question

Parse simplexml_load_string response

Avatar of dovercomputers
dovercomputers asked on
3 Comments1 Solution396 ViewsLast Modified:
Hello experts.

I am really struggling to get my head around this. I receive an xml response from a php rest api call. Working code is below:

$xmlReq = <<<END
<?xml version="1.0"?>
<OTA_VehLocSearchRQ xmlns:xsd="" xmlns:xsi="" Version="0" xmlns="">
      <RequestorID Type="1" ID="D740B0D6-9111-43DE-A3C3-FD923A2FFE9B" />
  <Vendor CompanyShortName="VHN,A4288CA0-AD96-47E8-957D-4963DACA85B3" />

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, '');
   curl_setopt ($ch, CURLOPT_POST, 1);
   curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Content-type: text/xml; charset=utf-8"));
   curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_POSTFIELDS, $xmlReq);
   $store = curl_exec ($ch);
   $xmlResponse = simplexml_load_string($store);

to which I have added

foreach ($xmlResponse->VehMatchedLocs->VehMatchedLoc as $value){
   echo "<br /><br />";

This gives me a response, see link CLICK HERE

So it is broken down into VehMatchedLoc which is perfect. How do I access the various levels from here? For example If want to build a select box with a list of the City Names how do I access [CityName] ?

If I can get my head around this all the pieces for the rest of the script will fall into place. I can re-use this code for the rest of the calls.

Hope you can help

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros