从包含标头的字符串获取XML字符串

时间:2015-04-14 12:08:30

标签: xml wsdl mime-types soap-client

我有WSDL服务的XML格式的响应和标题(服务做得不好,但我对此没有任何影响)。响应看起来像这样:

  --uuid:5ef54ff9-16d1-4675-823a-f692be71a142+id=295
  Content-ID: <http://tempuri.org/0>M
  Content-Transfer-Encoding: 8bitM
  Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"

  <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/ZalogujResponse</a:Action></s:Header><s:Body><ZalogujResponse xmlns="http://CIS/BIR/PUBL/2014/07"><ZalogujResult>s4e4c8u5h4s7s4y6z6p6</ZalogujResult></ZalogujResponse></s:Body></s:Envelope>
  --uuid:5ef54ff9-16d1-4675-823a-f692be71a142+id=295--

现在我需要从该响应中仅获取XML字符串。我知道我可以爆炸并从阵列中获取它,或者只是在第二次出现之后解析#34;&lt;&#34;但是我想要更全面地做...因为如果他们将添加任何标题或删除它我的脚本将停止工作,所以它是危险的解决方案。有没有更好的方法呢? 我有Symfony2应用程序(PHP)。

1 个答案:

答案 0 :(得分:0)

到目前为止,我只找到以下解决方案来解决与MTOM一起使用的XOP

    $response = 'YOUR XML STRING....'; //WSDL Response (with CURL or SOAP)

    //if resposnse content type is mtom strip away everything but the xml.
    if( strpos($response, "Content-Type: application/xop+xml") !== false){
        $tempstr = stristr($response, "<s:Envelope");
        $response = substr($tempstr, 0, strpos($tempstr, "</s:Envelope>")) . "</s:Envelope>";
    }
    return $response;