PHP - SimpleXML not returning object

时光怂恿深爱的人放手 提交于 2019-12-02 01:08:11

问题


I'm pretty stuck here on getting SimpleXML to return an object when I parse it a string that's part of an objects array.

$a = '<?xml version="1.0" encoding="ISO-8859-1"?><BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionId xmlns="">1145869290</sessionId><command echo="" xsi:type="UserCallForwardingAlwaysGetResponse" xmlns=""><isActive>false</isActive><forwardToPhoneNumber>43</forwardToPhoneNumber><isRingSplashActive>false</isRingSplashActive></command></BroadsoftDocument>';
$resultA = simplexml_load_string($a);
var_dump($resultA);

$b = $this->_request->_response->_body; // This is the same content as $a and is a string. 
$resultB = simplexml_load_string($b);   
var_dump($resultB);

The output of $resultA is an object with warning:

Warning: simplexml_load_string(): namespace warning : xmlns: URI C is not absolute in /var/www/html/Broadworks.php on line 103

The output of $resultB is a empty object?

Both $a and $b are the same strings.


回答1:


remove xmlns="C" from your xml string



来源:https://stackoverflow.com/questions/7092079/php-simplexml-not-returning-object

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