我已經嘗試過,並且一直無法想出一個解決方案。我的問題是這樣的: 我有一個SOAP信封響應是如下...SOAP信封解析與所有XMLNS - 不在Magento上工作
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:header>
<soapenv:body>
<mcu:prescreenusereligibilityresponse xmlns:mcu="http://www.ups.com/XMLSchema/XOLTWS/MCUserEligibility/v1.0">
<common:response xmlns:common="http://www.ups.com/XMLSchema/XOLTWS/Common/v1.0">
<common:responsestatus>
<common:code>1</common:code>
<common:description>Success</common:description>
</common:responsestatus>
</common:response>
<mcu:eligibilitystatuscode>3</mcu:eligibilitystatuscode>
</mcu:prescreenusereligibilityresponse>
</soapenv:body>
</soapenv:header>
</soapenv:envelope>
我然後訪問我的Mac這樣的元素:
$ns=array();
$xml=new SimpleXMLElement($string);
foreach($xml->getNamespaces(true) as $key=>$url){
$xml->registerXPathNamespace($key, $url);
$ns[]=strval($url);
}
print_r(strval($xml->children($ns[0])->header->body->children($ns[1])->prescreenusereligibilityresponse->eligibilitystatuscode));
用同樣的方法在單獨的Linux實例我在print_r
行發生錯誤,說最後一個孩子不能爲空。我已確認這些值是正確的。我也嘗試使用$xml->xpath('//mcu:eligibilitystatuscode')
沒有成功。
我真的堅持-_-
同樣的結果。我相當肯定'trim($ string)'會擺脫結束字符。 (我也試過) –
@DrewPeterson修剪只會在整個字符串的開始/結尾處刪除空格,而不是每一行。 –