从带有标头的字符串获取XML字符串

时间:2022-02-23 21:23:04

I have response from WSDL Service in XML format with headers (service was done bad but I don't have any influence on that). Response looks like that:

我有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--

Now i need to get only XML string from that response. I know that i can explode and get it from array or just parse after 2nd apperance of "<" but I want to do it more global... Because that way if they will add any header or remove it my scripts would stop working so it's dangerous solution. Is there a better way to do it ? I have Symfony2 Application (PHP).

现在我需要从该响应中仅获取XML字符串。我知道我可以爆炸并从数组中获取它或只是在第二次出现“<”之后进行解析但是我想要更全局...因为这样如果他们将添加任何标题或删除它我的脚本将停止工作所以这是危险的解决方案。有没有更好的方法呢?我有Symfony2应用程序(PHP)。

1 个解决方案

#1


0  

Till now I have found only the following solution to fix MTOM used with XOP:

到目前为止,我发现只有以下解决方案来修复与XOP一起使用的MTOM:

    $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;

#1


0  

Till now I have found only the following solution to fix MTOM used with XOP:

到目前为止,我发现只有以下解决方案来修复与XOP一起使用的MTOM:

    $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;