3

この SOAP 応答を解析して の値を取得する方法に関する推奨事項はnameありreport_typeますか? name には 2 つのインスタンスがあることに注意してください。1つは下report_typeに、もう1つは下にseverity

SOAP 応答は次のとおりです。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns1:getIRResponse xmlns:ns1="http://ws.icontent.idefense.com/V3/2">
         <ns1:return xsi:type="ns1:IRResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ns1:report_type>
               <ns1:id>0</ns1:id>
               <ns1:name>Original Vulnerability</ns1:name>
            </ns1:report_type>
            <ns1:severity>
                <ns1:id>0</ns1:id>
                <ns1:name>HIGH</ns1:name>
            </ns1:severity>
         </ns:return>
      </ns1:getIRResponse>
   </soapenv:Body>
</soapenv:Envelope>

私が使用しているPHPコードは次のとおりです。

<?php        
    $xml = simplexml_load_string($response);    
    $xml->registerXPathNamespace('ns1', 'http://ws.icontent.idefense.com/V3/2');

    foreach ($xml->xpath('//ns1:report_type/name') as $item)
    {
        echo 'Name: '.$item,'<br>';               
    } 
?>

PHP コードは何もエコーしません。使用する($xml->xpath('//ns1:name') as $item)と、両方の名前 (元の脆弱性と高) が返されます。

私は愚かな何かが欠けていることを知っています。助けていただけますか?前もって感謝します!

4

1 に答える 1

5

まず、この要素を修正しました

</ns:return>

そしてそれをに変更しました

</ns1:return>

両方のxpathセグメントで名前空間プレフィックスを複製することで、あなたが求めている結果が得られるようです

$xml = simplexml_load_string($response);    
$xml->registerXPathNamespace('ns1','http://ws.icontent.idefense.com/V3/2');
foreach ($xml->xpath('//ns1:report_type/ns1:name') as $item)
{
  echo 'Name: '.$item,'<br>';
}            

出力

Name: Original Vulnerability
于 2012-11-19T22:03:03.610 に答える