SimpleXML is not parsing my epp XML messages

安稳与你 提交于 2019-12-25 04:22:22

问题


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 xpathto 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!