title: How to access the data in this PHP XML response?
body: <p>I'm doing a request to a gov't website for validating a tax number. I get a pretty nested XML response and i'm pretty frustrated at the moment trying to parse and access the data.</p>
  
  <p>In essense this is the response:</p>
  
  <pre><code> &lt;params&gt;
      &lt;param&gt;
          &lt;value&gt;&lt;array&gt;&lt;data&gt;
              &lt;value&gt;&lt;string&gt;UstId_1&lt;/string&gt;&lt;/value&gt;
              &lt;value&gt;&lt;string&gt;SOMETAXNUM&lt;/string&gt;&lt;/value&gt;
          &lt;/data&gt;&lt;/array&gt;&lt;/value&gt;
      &lt;/param&gt;
      &lt;param&gt;
          &lt;value&gt;&lt;array&gt;&lt;data&gt;
              &lt;value&gt;&lt;string&gt;ErrorCode&lt;/string&gt;&lt;/value&gt;
              &lt;value&gt;&lt;string&gt;200&lt;/string&gt;&lt;/value&gt;
          &lt;/data&gt;&lt;/array&gt;&lt;/value&gt;
      &lt;/param&gt;
      &lt;param&gt;
           &lt;value&gt;&lt;array&gt;&lt;data&gt;
              &lt;value&gt;&lt;string&gt;UstId_2&lt;/string&gt;&lt;/value&gt;
              &lt;value&gt;&lt;string&gt;SECONDTAXNUM&lt;/string&gt;&lt;/value&gt;
           &lt;/data&gt;&lt;/array&gt;&lt;/value&gt;
      &lt;/param&gt; ....
  
  &lt;/params&gt;
  </code></pre>
  
  <p>I parse the result with <code>new SimpleXMLElement()</code> .</p>
  
  <p>But i have no success accessing what i truely need... And what i need is the "ErrorCode" Response (in this case its 200).</p>
  
  <p>This is what i had </p>
  
  <pre><code>$xml-&gt;["param"][1]-&gt;["value"]-&gt;['array']-&gt;["data"]-&gt;["value"‌​][1]-&gt;['string'];
  </code></pre>
  
  <p>Thanks to the answer i got, this is my poor solution to get the code i wanted:</p>
  
  <pre><code>        $xml = simplexml_load_string($xml_string);
          $result = $xml-&gt;xpath('param');
  
          $count = 0;
          while(list( , $node) = each($result)) {
              if ($count == 1){
                  return (string)$node-&gt;value[0]-&gt;array[0]-&gt;data-&gt;value[1]-&gt;{'string'};
              }
              $count ++;
          }
  </code></pre>