0
<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:body>
<providersearchbycityresponse xmlns="https://ccrrwsqa.naccrra.org">
<?xml version="1.0" encoding="utf-16"?>
<Providers>
  <Provider>
   <NameID>
     <![CDATA[657]]>
   </NameID>
   <ParentID />
   <OrganizationName>
     <![CDATA[Early Childhood Training Network]]>
   </OrganizationName>
   <PhoneNumber>
     <![CDATA[(605) 773-2169]]>
   </PhoneNumber>
 </Provider>
</Providers>
</providersearchbycityresponse>
</s:body>
</s:envelope>

I am getting above XML as string from API call, but I am not finding way how can I parse above response so that I can get data of all providers. complete response here

  • look at `simpleXML` php library...http://php.net/manual/en/simplexml.examples.php – Nishant Solanki Apr 06 '15 at 07:22
  • Nothing is working for me. I have added complete response on pastebin. Please help. – Poonam Ghangas Apr 06 '15 at 07:40
  • While parsing I am getting empty SimpleXMLElement Object ( ). – Poonam Ghangas Apr 06 '15 at 08:07
  • It might look empty with `print_r` or `var_dump.` use the [`::asXML()`](http://php.net/simplexmlelement.asxml) method of it to really see what is in there. The XML normally doesn't change only you load it, unless the XML is broken, but then you have seen in the error reporting if you have that activated. If not, it's the first step to do before developing: [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456). – hakre Apr 06 '15 at 08:15
  • Regarding the emptyness, see as well [SimpleXML and print_r() - why is this empty?](http://stackoverflow.com/q/3109302/367456) - The PHP manual has an introductory chapter on how to handle XML with SimpleXML: [Basic SimpleXML usage](http://php.net/simplexml.examples-basic) – hakre Apr 06 '15 at 08:21
  • $myxmlresponse = $client->responseData; $xml = new SimpleXMLElement($myxmlresponse); $string = $xml->asXML(); $xml = simplexml_load_string($string); print_r($xml); This is the PHP code I am using. still not getting way to get the data as array or object?? – Poonam Ghangas Apr 06 '15 at 08:50
  • No you won't. As I wrote using `print_r` on a **SimpleXMLelement** doesn't make it. Imagine you've got a database driver that allows you to connect to a database. And then you use `print_r` on the connection object. Do you expect it to show you all the data that is in the databse? Most likely not, it will give you - if at all - some very limited information only. That's the same with a **SimpleXMLElement**, you have to use `$xml->asXML('php://output');` instead to see which XML the document contains. You then access the document as outlined in the PHP manual basic usage I linked above. – hakre Apr 06 '15 at 14:26

0 Answers0