[英]Retrieve DATA from XML with Simplexml
我正在尝试从使用 Symfony2 和 php 5.6 的 XML SOAP 响应中提取值,我已经阅读了文档并尝试了许多方法,但仍然无法获取数据
这是我的 XML 字符串
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:provisioningWithDataResponse xmlns="URL" xmlns:ns2="http://URL">
<ns2:provisioningReturn>
<date>2016-02-26T09:17:49.648+01:00</date>
<messageId>642176832</messageId>
<returnCode>1</returnCode>
<returnMessage>Code: 6 Message: SQL query failed </returnMessage>
</ns2:provisioningReturn>
</ns2:provisioningWithDataResponse>
</S:Body>
</S:Envelope>
我试过这个来获取数据并将其存储在会话中,但似乎$xml
始终为空,因为我总是收到此错误消息
注意:尝试获取非对象的属性
代码:
$xml=simplexml_load_string($order_return);
$session->set("Respense",(string)$xml->children('ns2',true)->provisioningReturn[0]->returnMessage);
知道如何检索returnMessage
值吗? 谢谢
试试下面的代码:
(string)
// $xml is the node: S:Envelope
$xml->children('S', true) // => node: S:Body
->children('ns2', true) // => node: ns2:provisioningWithDataResponse
->children('ns2', true) // => ns2:provisioningReturn
->children()
->returnMessage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.