问题
I am trying to extract information out of a return xml epp messages from SIDN
But i am not abbel to get some of the variables out of this messages. I manage to get the result code and messages.
$domaininfo = xml messages that can be seen at : http://pastebin.com/HbXMkdD3
$xml = new SimpleXMLElement($domeininfo);
// check result code
if (isset($xml->response->result))
{ foreach($xml->response->result->attributes() as $name => $value) {
if ($name === 'code')
{ $code = $value; }
}
}
if ($code == '1000')
{
$domeinnaamuitxml = $xml->response->{'resData'}->{'domain:infData'}->{'domain:name'};
$techcuitxml = $xml->response->{'resData'}->{'domain:infData'}->{'domain:contact type="tech"'};
$admincuitxml = $xml->response->{'resData'}->{'domain:infData'}->{'domain:contact type="admin"'};
echo "Domein naam : $domeinnaamuitxml \n";
echo "Admin C : $admincuitxml \n";
echo "Tech C : $techcuitxml \n";
}
What is it that i am doing wrong
It seam as soon as there is a : - = or " in the tag there is a problem
all help is surely welkom
回答1:
use xpath
to select namespaced elements with simplexml
:
$domeinnaamuitxml = (string)$xml->xpath("//domain:name"}[0];
Comment: The above code requires PHP >= 5.4 because of the [0]
(array dereferencing). In an older version of PHP, do:
$domeinnaamuitxml = $xml->xpath("//domain:name"};
$domeinnaamuitxml = (string)$domeinnaamuitxml[0];
see it working: https://eval.in/101915
来源:https://stackoverflow.com/questions/21788253/simplexml-is-not-parsing-my-epp-xml-messages