2015-04-14 81 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; 
相關問題