2015-04-14 82 views
1

我以具有头文件的XML格式从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字符串。我知道我可以爆炸并从数组中获取它,或者只是在第二次出现“<”后解析,但我想更全局地做它...因为这样,如果他们将添加任何标题或将其删除,我的脚本将停止工作这是危险的解决方案。有没有更好的方法来做到这一点? 我有Symfony2应用程序(PHP)。

+0

在哪种语言,你处理的反应如何? – Kanti

+0

Symfony2与PHP ;-) –

+0

我认为这[链接](http://stackoverflow.com/questions/9183178/ph​​p-curl-retrieving-response-headers-and-body-in-a-single-request)将帮你。 – Kanti

回答

0

到现在我只找到了以下解决方案来解决MTOMXOP使用:

$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; 
相关问题