如何使用名称空间解析SOAP XML-answer

时间:2018-08-17 13:00:48

标签: php xml parsing simplexml

我有XML-answer,如下所示。

如何通过php和SimpleXml正确解析此答案? 现在,我使用“ str_replace”删除字符串,例如“ soap:Envelope”,“ simplexml_load_string”等。 是否有更多正确的变体可以解析字符串以获取字段“ code”和“ message”?

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Body>
    <example:app_response xmlns:m="urn:QWERTY/YTREWQ/application">
      <code>0</code>
      <message/>
    </example:app_response>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope></soap:Body></soap:Envelope>

1 个答案:

答案 0 :(得分:0)

如果将此xml作为字符串,那么我将通过preg_match调用获取代码。像<code>(.+)</code>

这样的模式
相关问题