php7 - php 解析SOAP的xml失败
ringa_lee
ringa_lee 2017-05-16 13:14:49
0
2
2733
$xmlStr = <<<xml
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <client_insetResponse xmlns="http://120.26.103.193:2017/webservices/">
            <client_insetResult>0|</client_insetResult>
        </client_insetResponse>
    </soap:Body>
</soap:Envelope>
xml;
$xmlObj = simplexml_load_string($xmlStr);
var_dump($xmlObj);

上面代码打印结果为空对象,说明解析失败

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
某草草

不能识别xmlns:soap,xmlns:xsi,xmlns:xsd

可以把xmlns:soap改为xmlns-soap再处理。

仅有的幸福

soap的命名空间不被识别,参考下面代码:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <client_insetResponse xmlns="http://127.0.0.1/webservices/">
            <client_insetResult>0|</client_insetResult>
        </client_insetResponse>
    </soap:Body>
</soap:Envelope>
xml;
    
$xmlObj = simplexml_load_string($xmlStr);
$xmlObj->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$result = $xmlObj->xpath("soap:Body");

print_r($result);
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!