我是XMl的新手。我想在以下xml中提取状态值.i不知道如何在php中执行此操作。这是我从API调用获得的响应。
<soapenv:envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:body>
<savesalesorderresponse xmlns="http://www.smartturn.com/services/OccamService/sales-order">
<uploadresponse>
<ns1:externalrefid xmlns:ns1="http://www.smartturn.com/services/occamtypes">007</ns1:externalrefid>
<ns2:status xmlns:ns2="http://www.smartturn.com/services/occamtypes">SUCCESS</ns2:status>
<ns6:systemid xmlns:ns6="http://www.smartturn.com/services/occamtypes">SO-059241</ns6:systemid>
</uploadresponse>
</savesalesorderresponse>
</soapenv:body>
</soapenv:envelope>
解决方案代码将不胜感激 提前谢谢
答案 0 :(得分:2)
您需要做的就是使用registerXPathNamespace
$xml = new SimpleXMLElement($data);
$xml->registerXPathNamespace("ns", "http://www.smartturn.com/services/occamtypes");
$status = $xml->xpath('//ns:status');
$status = (string) $status[0];
print($status);
输出
SUCCESS
答案 1 :(得分:-1)
最简单的方法是使用SimpleXML