2012-10-12 48 views
2

我是XMl的新手。我想提取以下xml中的狀態值。我不知道如何在php中執行此操作。這是我從API調用中獲得的響應。從soapenv信封xml提取值在php

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

解決方案的代碼可以理解的提前 感謝

回答

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 
+0

thanks.that很棒 –

+0

不客氣Sheikh詹姆斯 – Baba

0

最簡單的方法是使用SimpleXML

+0

使用php的simpleXMl函數我沒有得到它的功能..用這個xml解析代碼將不勝感激 –