0
我在過去的16個小時裏一直在桌子上敲我的頭,試圖弄清楚爲什麼我不能從這個請求中解析我的XML SOAP響應。我已經走過了超越stackoverflow試圖找到一個解決方案,似乎無法找到正確的答案。PHP CURL SOAP XML分析命名空間警告
我意識到我可能錯過了一個關鍵點,但我似乎無法找到它。
//Response From Server
$r = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><RegisterMarketResponse xmlns="http://tempuri.org/"><RegisterMarketResult xmlns:a="http://schemas.datacontract.org/2004/07/Synectic.TheMarket.Domain.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:Cabinets xmlns:b="http://schemas.datacontract.org/2004/07/Synectic.TheMarket.Domain"><b:Cabinet><b:AssetId>1</b:AssetId><b:AssetNumber>001</b:AssetNumber><b:Model>*****</b:Model><b:ModelCategory>Snack</b:ModelCategory><b:Products>2</b:Products></b:Cabinet></a:Cabinets><a:CompanyId>{*****}</a:CompanyId><a:CompanyName>****</a:CompanyName><a:DateCreated>2016-07-16T07:55:15.84</a:DateCreated><a:Id>1</a:Id><a:MarketNumber>****</a:MarketNumber></RegisterMarketResult></RegisterMarketResponse></s:Body></s:Envelope>';
// converting
$response1 = str_replace("<s:Body>","",$r);
$response2 = str_replace("</s:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
print_r($parser);
這給了我的
SimpleXMLElement Object ([RegisterMarketResponse] => SimpleXMLElement Object ([RegisterMarketResult] => SimpleXMLElement Object ()))
響應但是,如果我改變
// converting
$response1 = str_replace("<s:Body>","",$r);
$response2 = str_replace("</s:Body>","",$response1);
到
// converting
$response1 = str_replace('<RegisterMarketResult xmlns:a="http://schemas.datacontract.org/2004/07/Synectic.TheMarket.Domain.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">',"",$r);
$response2 = str_replace("</RegisterMarketResult>","",$response1);
我得到
Warning: simplexml_load_string(): namespace error : Namespace prefix a on Cabinets is not defined in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): nets xmlns:b="http://schemas.datacontract.org/2004/07/Synectic.TheMarket.Domain" in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string():^in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): namespace error : Namespace prefix a on CompanyId is not defined in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): /b:ModelCategory><b:Products>2</b:Products></b:Cabinet></a:Cabinets><a:CompanyId in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string():^in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): namespace error : Namespace prefix a on CompanyName is not defined in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): ><a:CompanyId>{*****}</a:CompanyId><a:CompanyName in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string():^in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): namespace error : Namespace prefix a on DateCreated is not defined in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): ****}</a:CompanyId><a:CompanyName>**</a:CompanyName><a:DateCreated in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string():^in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): namespace error : Namespace prefix a on Id is not defined in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): e>**</a:CompanyName><a:DateCreated>2016-07-16T07:55:15.84</a:DateCreated><a:Id in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string():^in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): namespace error : Namespace prefix a on MarketNumber is not defined in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string(): :DateCreated>2016-07-16T07:55:15.84</a:DateCreated><a:Id>1</a:Id><a:MarketNumber in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
Warning: simplexml_load_string():^in /Applications/XAMPP/xamppfiles/htdocs/untitled/index.php on line 66
object(SimpleXMLElement)#1 (0) { }
這似乎是更正確的方向,但仍然破碎。
任何人都可以協助解析這個東西嗎?