使用键和值对在PHP中解析Soap响应

时间:2015-08-24 14:31:33

标签: php parsing curl soap xml-parsing

我得到以下肥皂响应。

    <soapenv>
    <soapenv:Body><res:ResultMsg >
    <Result>
        <ResultType>0</ResultType>
        <ResultCode>0</ResultCode>
        <ResultDesc>Processing</ResultDesc>
        <OriginatorID>2545imt56764</OriginatorID>
    <ResultParameters>
        <ResultParameter>
        <Key>firstname</Key>
        <Value>john</Value>
        </ResultParameter>
    <ResultParameter>
        <Key>lastname</Key>
        <Value>doe</Value>
    </ResultParameter>
    <ResultParameter>
        <Key>Country</Key>
        <Value>xxxx</Value>
    </ResultParameter>
    </ResultParameters>
    </Result>
   </res:ResultMsg>
   </soapenv:Body>
   </soapenv:Envelope>

我想从代码中检索名字和姓氏。以下是我正在使用的代码。

  $doc->loadXML($rawXML);
    $ResultCode = $doc->getElementsByTagName('ResultCode')->item(0)->nodeValue;
    $ResultDesc = $doc->getElementsByTagName('ResultDesc')->item(0)->nodeValue;
    $OriginatorID = $doc->getElementsByTagName('OriginatorID')->item(0)->nodeValue;
    $name = $doc->getElementsByTagName('value')->item(0)->nodeValue;
    echo $ResultCode"," ;
    echo $ResultDesc"," ;
    echo $OriginatorID",";
    echo $name",";

我如何能够检索姓氏和国家/地区值

0 个答案:

没有答案