2016-12-19 8 views
0

シンプルかもしれませんが、私はこだわっています。 XML文字列をPHPオブジェクトに変換したい。私のXML文字列は次のとおりです。simplexml_load_stringは空の結果を返します

$a = '<?xml version="1.0" encoding="utf-8"?> 
     <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
      <soap:Body> 
       <VerifyTxnResponse xmlns="http://www.exmlplekhe.com/"> 
        <VerifyTxnResult>BID &lt;11467&gt;</VerifyTxnResult> 
       </VerifyTxnResponse> 
      </soap:Body> 
     </soap:Envelope>'; 

私はvar_dump(simplexml_load_string($a));を試してみましたが、それは空のSimpleXMLElementオブジェクトを返します。私はVerifyTxnResultノードを取得したいです。私は、&lt;11467&gt;が問題を引き起こしていると思う。可能な解決策は何でしょうか?

ありがとうございました。

+1

関数は 'SimpleXMLElement'オブジェクトを返します。 「空の結果」とはどういう意味ですか?あなたは何をしようとしていますか? –

+0

正確に何が返されますか? –

+0

@ruslan空のSimpleXMLElementオブジェクトを返します – vijayrana

答えて

2

私はVerifyTxnResultノード

simplexml_load_string機能は、実際にあなたが投稿XMLのための空でないSimpleXMLElementのインスタンスを返しますを取得したいです。

名前空間を登録し、xpath方法でノードをフェッチ:

$se = simplexml_load_string($a); 

$se->registerXPathNamespace('r', 'http://www.nibl.com.np/'); 

foreach ($se->xpath('//r:VerifyTxnResult') as $result) { 
    var_dump((string)$result); 
} 

サンプル出力

string(11) "BID <11467>" 
関連する問題