title: Simple XML load file and extracting information from the XML result
body: <p>What I have here is an XML based API lookup. I am loading the URL that's xml for the most part, into <code>simple_xml_load_file()</code>. </p>
  
  <p>Pasting the URL into the browser, gives the XML output. </p>
  
  <p>You can try the lookup link <a href="http://api.peoplesearchxml.com/SearchServicePublic.asmx/SearchXML?sSearchRequest=&lt;search&gt;&lt;searchType&gt;PartnerPeopleSearchByPhoneACW&lt;/searchType&gt;&lt;searchCriteria&gt;&lt;phone&gt;5128435436&lt;/phone&gt;&lt;/searchCriteria&gt;&lt;identification&gt;&lt;websiteKey&gt;7&lt;/websiteKey&gt;&lt;partnerID&gt;XYZCalledYou.com&lt;/partnerID&gt;&lt;partnerPassword&gt;eshwarrocks&lt;/partnerPassword&gt;&lt;ipAddress&gt;127.0.0.1&lt;/ipAddress&gt;&lt;/identification&gt;&lt;formatting&gt;&lt;maxResults&gt;5&lt;/maxResults&gt;&lt;/formatting&gt;&lt;/search&gt;" rel="nofollow">here</a>, </p>
  
  <p>I am loading the exact same link with quotes into the <code>simplexml_load_file</code>.</p>
  
  <p>Where I am stuck is the extracting part, I would like to extract State, Carrier, City, County and the Phone type from the XML result. </p>
  
  <p>This is my code to extract the <code>State</code></p>
  
  <pre><code>$state = $simpleXML-&gt;searchService-&gt;searchResult-&gt;dataset-&gt;phoneInfo-&gt;rateCenter['state'];
  </code></pre>
  
  <p>It fails for some reason I don't know why. Doing a <code>echo</code> of <code>$simpleXML</code> doesn't gives any output. </p>
  
  <p>So I am failing either with loading the XML URL or extracting, which is now clear with loading the XML. </p>
  
  <p>So I am pasting the entire code for you to take a look,</p>
  
  <pre><code>&lt;?php
  
  $phoneNumber = 5128435436;
  $context  = stream_context_create(array('http' =&gt; array('header' =&gt; 'Accept: application/xml')));
  
  $simpleXML = 'http://api.peoplesearchxml.com/SearchServicePublic.asmx/SearchXML?sSearchRequest=&lt;search&gt;&lt;searchType&gt;PartnerPeopleSearchByPhoneACW&lt;/searchType&gt;&lt;    searchCriteria&gt;&lt;phone&gt;'.$phoneNumber.'&lt;/phone&gt;&lt;/searchCriteria&gt;&lt;identification&gt;&lt;websiteKey&gt;7&lt;/websiteKey&gt;&lt;partnerID&gt;XYZCalledYou.com&lt;/partnerID&gt;&lt;partnerPassword&gt;eshwarrocks&lt;/    partnerPassword&gt;&lt;ipAddress&gt;127.0.0.1&lt;/ipAddress&gt;&lt;/identification&gt;&lt;formatting&gt;&lt;maxResults&gt;5&lt;/maxResults&gt;&lt;/formatting&gt;&lt;/search&gt;';    
  
  $xml = file_get_contents($simpleXML, false, $context);
  $xml = simplexml_load_string($xml);
  
  $state = $simpleXML-&gt;searchService-&gt;searchResult-&gt;dataset-&gt;phoneInfo-&gt;rateCenter['state'];
  $carrier = $simpleXML-&gt;searchResult-&gt;dataset-&gt;phoneSearch['company'];
  $city = $simpleXML-&gt;searchResult-&gt;dataset-&gt;phoneSearch['city'];
  $county = $simpleXML-&gt;searchResult-&gt;dataset-&gt;phoneSearch['county'];
  $phoneType = $simpleXML-&gt;searchResult-&gt;dataset-&gt;phoneSearch['lineType'];
  
  echo $simpleXML. '&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;';
  echo 'Phone Number: '.$phoneNumber.'&lt;br /&gt;';
  echo 'State: '.$state.'&lt;br /&gt;';
  echo 'Carrier: '.$carrier.'&lt;br /&gt;';
  echo 'City: '.$city.'&lt;br /&gt;';
  echo 'County: '.$county.'&lt;br /&gt;';
  echo 'Phone Type: '.$phoneType.'&lt;br /&gt;';
  
  ?&gt;
  </code></pre>
  
  <p>Thank you for taking your time looking into this, much appreciated.</p>