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.
In essense this is the response:
<params>
<param>
<value><array><data>
<value><string>UstId_1</string></value>
<value><string>SOMETAXNUM</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>ErrorCode</string></value>
<value><string>200</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>UstId_2</string></value>
<value><string>SECONDTAXNUM</string></value>
</data></array></value>
</param> ....
</params>
I parse the result with new SimpleXMLElement()
.
But i have no success accessing what i truely need... And what i need is the "ErrorCode" Response (in this case its 200).
This is what i had
$xml->["param"][1]->["value"]->['array']->["data"]->["value"][1]->['string'];
Thanks to the answer i got, this is my poor solution to get the code i wanted:
$xml = simplexml_load_string($xml_string);
$result = $xml->xpath('param');
$count = 0;
while(list( , $node) = each($result)) {
if ($count == 1){
return (string)$node->value[0]->array[0]->data->value[1]->{'string'};
}
$count ++;
}