本文整理汇总了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;
}
}
//.........这里部分代码省略.........