當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SimpleXMLObject::getName方法代碼示例

本文整理匯總了PHP中SimpleXMLObject::getName方法的典型用法代碼示例。如果您正苦於以下問題:PHP SimpleXMLObject::getName方法的具體用法?PHP SimpleXMLObject::getName怎麽用?PHP SimpleXMLObject::getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleXMLObject的用法示例。


在下文中一共展示了SimpleXMLObject::getName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadXML

 /**
  * Takes in XML data and converts it to an array for the object to use.
  * @param SimpleXMLObject $xml <p>XML Product data from Amazon</p>
  * @return boolean <b>FALSE</b> if no XML data is found
  */
 public function loadXML($xml)
 {
     if (!$xml) {
         return false;
     }
     $this->data = array();
     //Categories first
     if ($xml->getName() == 'GetProductCategoriesForSKUResult' || $xml->getName() == 'GetProductCategoriesForASINResult') {
         $this->loadCategories($xml);
         return;
     }
     if ($xml->getName() != 'Product') {
         return;
     }
     //Identifiers
     if ($xml->Identifiers) {
         foreach ($xml->Identifiers->children() as $x) {
             foreach ($x->children() as $z) {
                 $this->data['Identifiers'][$x->getName()][$z->getName()] = (string) $z;
             }
         }
     }
     //AttributeSets
     if ($xml->AttributeSets) {
         $anum = 0;
         foreach ($xml->AttributeSets->children('ns2', true) as $aset) {
             foreach ($aset->children('ns2', true) as $x) {
                 if ($x->children('ns2', true)->count() > 0) {
                     //another layer
                     foreach ($x->children('ns2', true) as $y) {
                         if ($y->children('ns2', true)->count() > 0) {
                             //we need to go deeper
                             foreach ($y->children('ns2', true) as $z) {
                                 if ($z->children('ns2', true)->count() > 0) {
                                     //we need to go deeper
                                     $this->log('Warning! Attribute ' . $z->getName() . ' is too deep for this!', 'Urgent');
                                 } else {
                                     $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()][$z->getName()] = (string) $z;
                                 }
                             }
                         } else {
                             $this->data['AttributeSets'][$anum][$x->getName()][$y->getName()] = (string) $y;
                         }
                     }
                 } else {
                     //Check for duplicates
                     if (array_key_exists('AttributeSets', $this->data) && array_key_exists($anum, $this->data['AttributeSets']) && array_key_exists($x->getName(), $this->data['AttributeSets'][$anum])) {
                         //check for previous cases of duplicates
                         if (is_array($this->data['AttributeSets'][$anum][$x->getName()])) {
                             $this->data['AttributeSets'][$anum][$x->getName()][] = (string) $x;
                         } else {
                             //first instance of duplicates, make into array
                             $temp = array($this->data['AttributeSets'][$anum][$x->getName()]);
                             $this->data['AttributeSets'][$anum][$x->getName()] = $temp;
                             $this->data['AttributeSets'][$anum][$x->getName()][] = (string) $x;
                         }
                     } else {
                         //no duplicates
                         $this->data['AttributeSets'][$anum][$x->getName()] = (string) $x;
                     }
                 }
             }
             $anum++;
         }
     }
     //Relationships
     if ($xml->Relationships) {
         foreach ($xml->Relationships->children() as $x) {
             foreach ($x->children() as $y) {
                 foreach ($y->children() as $z) {
                     foreach ($z->children() as $zzz) {
                         $this->data['Relationships'][$x->getName()][$y->getName()][$z->getName()][$zzz->getName()] = (string) $zzz;
                     }
                 }
             }
         }
     }
     //CompetitivePricing
     if ($xml->CompetitivePricing) {
         //CompetitivePrices
         foreach ($xml->CompetitivePricing->CompetitivePrices->children() as $pset) {
             $pnum = (string) $pset->CompetitivePriceId;
             $temp = (array) $pset->attributes();
             $belongs = $temp['@attributes']['belongsToRequester'];
             $con = $temp['@attributes']['condition'];
             $sub = $temp['@attributes']['subcondition'];
             $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['belongsToRequester'] = $belongs;
             $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['condition'] = $con;
             $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['subcondition'] = $sub;
             foreach ($pset->Price->children() as $x) {
                 //CompetitivePrice->Price
                 foreach ($x->children() as $y) {
                     $this->data['CompetitivePricing']['CompetitivePrices'][$pnum]['Price'][$x->getName()][$y->getName()] = (string) $y;
                 }
             }
//.........這裏部分代碼省略.........
開發者ID:zaffar-saffee,項目名稱:laravel-5-amazon-mws-persistent,代碼行數:101,代碼來源:AmazonProduct.php


注:本文中的SimpleXMLObject::getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。