本文整理汇总了PHP中SimpleXmlElement::getSafeParent方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXmlElement::getSafeParent方法的具体用法?PHP SimpleXmlElement::getSafeParent怎么用?PHP SimpleXmlElement::getSafeParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXmlElement
的用法示例。
在下文中一共展示了SimpleXmlElement::getSafeParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPath
/**
* Gets a path to a node via SPL Stack implementation
*
* Pass in the child node and will recurse up the XML tree to print out
* the path in the tree to that node
*
* <config>
* <path>
* <to>
* <node>
* Node Value
* </node>
* </to>
* </path>
* </config>
*
* If you pass in the "node" object, this will print out
* config/path/to/node/
*
* @param SimpleXmlElement $element Child element to find path to
*
* @return string
* @access public
*/
public function getPath(SimpleXmlElement $element)
{
$this->_iterator->push($element->getName() . '/');
if (!$element->getSafeParent()) {
return $this->_iterator->pop();
}
return $this->getPath($element->getParent()) . $this->_iterator->pop();
}
示例2: getPath
/**
* Gets a path to a node via array implementation
*
* Pass in the child node and will recurse up the XML tree to print out
* the path in the tree to that node
*
* <config>
* <path>
* <to>
* <node>
* Node Value
* </node>
* </to>
* </path>
* </config>
*
* If you pass in the "node" object, this will print out
* config/path/to/node/
*
* @param SimpleXmlElement $element Child element to find path to
*
* @return string
* @access public
*/
public function getPath(SimpleXmlElement $element)
{
$this->_iterator[] = $element->getName() . '/';
if (!$element->getSafeParent()) {
return array_pop($this->_iterator);
}
return $this->getPath($element->getParent()) . array_pop($this->_iterator);
}