这是我用于解析xml代码的php代码,如下所示:
$name = '<?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>
<QueryReportResponse xmlns="nPAY">
<QueryReportResult><QueryReportResponse xmlns="nPAY" />
</QueryReportResult>
</QueryReportResponse>
</soap:Body>
</soap:Envelope>';
$xml = simplexml_load_string($name);
var_dump($xml);
但是我得到了如下所述的这种错误:
Warning: simplexml_load_string(): namespace warning : xmlns: URI nPAY is not absolute in C:\xampp\htdocs\test.php on line 56
Warning: simplexml_load_string(): <QueryReportResponse xmlns="nPAY"> in C:\xampp\htdocs\test.php on line 56
Warning: simplexml_load_string(): ^ in C:\xampp\htdocs\test.php on line 56
object(SimpleXMLElement)#1 (0) { }
我错过了什么吗?如何解析这种肥皂反应?
答案 0 :(得分:0)
删除soap信封和soap body标签,并在xmlns的URI部分添加http://做了一些技巧。