1

SOAP ui を完全に使用して SOAP 呼び出しの SOAP 応答を取得していますが、php で同じものを呼び出すと、必要な要素 (この場合はCreditId ) にトラバースできません。

以下は、SOAP ui を使用して取得した SOAP 応答です。

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
   <soap-env:Header/>
   <soap-env:Body>
      <n0:getProjectCreditListResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
         <EUserGuid>33/XIcx+3/GxWABQVoJXWA==</EUserGuid>
         <EtCurrCreditList>
            <item>
               <PhaseId/>
               <CreditcategoryDescrption>Project Information Forms</CreditcategoryDescrption>
               <CreditId>CSD1GSP1L-1000008140</CreditId>
            </item>
            <item>
               <PhaseId/>
               <CreditcategoryDescrption>Project Information Forms</CreditcategoryDescrption>
               <CreditId>CSD1GSP2L-1000008140</CreditId>
            </item>
</EtCurrCreditList>
         <EtErrorLogInfo/>
      </n0:getProjectCreditListResponse>
   </soap-env:Body>
</soap-env:Envelope>

今、私はサイトでさまざまな同様の質問を調べました。目的の要素を取得するには、次のようにすることをお勧めします。

$client = new SoapClient('wsdl file path',array('trace'=>1,'exceptions'=>1);
$res = $client->getCreditFormDataXml(array(input arguments));

    $xml = simplexml_load_string($res);
    $xml->registerXPathNamespace('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
    $xml->registerXPathNamespace('n0', 'urn:sap-com:document:sap:soap:functions:mc-style');
    foreach ($xml->xpath('//EtCurrCreditList//item//CreditId') as $item)
    {
        var_dump($item);
    }

ただし、次のエラーが表示されます

警告: simplexml_load_string() は、パラメーター 1 が文字列であることを想定しています

$res変数を文字列に変換しようとしましたが、エラーが発生します

クラス stdClass のオブジェクトを文字列に変換できませんでした

しかし、var_dump($res)を実行すると、次のような出力が得られます。

object(stdClass)[2]
  public 'EUserGuid' => string 'ß×!Ì~ßñ±X�PV‚WX' (length=16)
  public 'EtCurrCreditList' => 
    object(stdClass)[3]
  public 'EtErrorLogInfo' => 
    object(stdClass)[4]

コードが EtCurrCreditList のサブノードに移動しないのはなぜですか。これにより、コードを処理して目的の値を取得できます。- 解決済み

最終出力:

stdClass Object
(
    [EUserGuid] => ß×!Ì~ßñ±XPV‚WX
    [EtCurrCreditList] => stdClass Object
        (
            [item] => Array
                (
                    [0] => stdClass Object
                        (
                            [PhaseId] => 
                            [PhaseDescription] => 
                            [CreditcategoryId] => CSD1GSL-1000008140
                            [CreditcategoryDescrption] => Project Information Forms
                            [CreditId] => CSD1GSP1L-1000008140
                         )
            [1] => stdClass Object
                        (
                            [PhaseId] => 
                            [PhaseDescription] => 
                            [CreditcategoryId] => CSD1GSL-1000008140
                            [CreditcategoryDescrption] => Project Information Forms
                            [CreditId] => CSD1GSP2L-1000008140
            )
            [2] => stdClass Object
                        (
                            [PhaseId] => 
                            [PhaseDescription] => 
                            [CreditcategoryId] => CSD1GSL-1000008140
                            [CreditcategoryDescrption] => Project Information Forms
                            [CreditId] => CSD1GSP3L-1000008140
            )
        )

        )

    [EtErrorLogInfo] => stdClass Object
        (
        )
4

1 に答える 1