2016-12-12 12 views
0

私は、SimpleXMLを使用して解析する外部エンティティによって生成されたXMLファイルを持っています。 私の問題は、クライアントから与えられたマッピングで、私が必要とする情報を得るための条件がいくつかあることです。 exempleについてはSimpleXML:解析ルールで条件付きのノード値を取得する方法は?

、クライアントコードのマッピングは次のようなものです:E1ADRM1\PARTNER_Q=OSO\E1ADRE1\EXTEND_Dウィッヒは、クライアントのコードはウィッヒが多くPARTNER_Qタグのいずれかにネストされ、EXTEND_Dタグの値であることを意味します。 OSOの値を持つもの。

私は今日SimpleXMLを探索し始めているので、この情報をどのように取得するのか分かりません。

これまで読んだことは、ノードの情報を取得してそのプロパティにアクセスするのはかなり簡単です。単一PARTNER_Qなしの条件私は場合は、私の$clientCodeだろう$xml->E1ADRM1->PARTNER_Q->E1ADRE1->EXTEND_D(右?)

私は情報がこのことを念頭に置いてPARTNER_Q=OSO状態を有する得ることができる方法上の任意のヒント?

ありがとうございます。

答えて

0

今後の参考として、このコードを私がどのように解決したかをここに示します。 私が見つけたwell written answerのコードをベースにしました。

$root = $xml->IDOC; 
$shippingPoints = array(); 
// Go through the list of OTs  
foreach($root->E1EDL20 as $ot) { 

    // Instanciate empty OT 
    $otInfo = emptyOt(); 
    $otInfo["refOt"] = trim($ot->VBELN); 

    // Go through partner to get the wanted items 
    foreach ($ot->E1ADRM1 as $partner) { 
      switch ($partner->PARTNER_Q) { 
        case "OSO": 
          $otInfo["codeLoader1"] = trim($partner->E1ADRE1->EXTEND_D); 

          break; 
        case "OSP": 
          $otInfo["refShip"] = trim($partner->PARTNER_ID); 
          // get the shipping info if not already fetched 
          if(!isset($shippingPoints[$otInfo["refShip"]])) { 
            $shippingPoints[$otInfo["refShip"]] = Whouses::getWhouseAddressByCode($otInfo["refShip"]); 
          } 
          // assign values 
          $otInfo["brandNameShip"] = $shippingPoints[$otInfo["refShip"]]["name"]; 
          $otInfo["addrShip1"] = $shippingPoints[$otInfo["refShip"]]["address"]; 
          $otInfo["cityShip"] = $shippingPoints[$otInfo["refShip"]]["city"]; 
          $otInfo["zipShip"] = $shippingPoints[$otInfo["refShip"]]["zipcode"]; 
          $otInfo["countryShip"] = $shippingPoints[$otInfo["refShip"]]["country"]; 

          break; 
        case "WE": 
          $otInfo["refDeliv"] = trim($partner->PARTNER_ID); 
          $otInfo["addrDeliv1"] = trim($partner->STREET1); 
          $otInfo["cityDeliv"] = trim($partner->CITY1); 
          $otInfo["zipDeliv"] = trim($partner->POSTL_COD1); 
          $otInfo["countryDeliv"] = trim($partner->COUNTRY1); 
        default: 
          // do nothing 
          break; 
      } 
    } 

    // Go through the dates info to get the wanted items 
    foreach ($ot->E1EDT13 as $qualf) { 
      switch ($qualf->QUALF) { 
        case "006": 
          $dtDeliv = trim($qualf->NTANF); 
          $timeDeliv = trim($qualf->NTANZ); 
          $otInfo["initialDtDeliv"] = convertToOtDateFormat($dtDeliv, $timeDeliv); 

          break; 
        case "007": 
          $initialDtShip = trim($qualf->NTANF); 
          $timeInitialDtShip = trim($qualf->NTANZ); 
          $otInfo["initialDtShip"] = convertToOtDateFormat($initialDtShip, $timeInitialDtShip); 

          break; 
        default: 
          // do nothing 
          break; 
      } 
    } 
} 

これは誰かを助けるでしょう!

関連する問題