本文整理汇总了PHP中XMLElement::replaceChildAt方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLElement::replaceChildAt方法的具体用法?PHP XMLElement::replaceChildAt怎么用?PHP XMLElement::replaceChildAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::replaceChildAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertAction
/**
* This function allows a user to insert an Action button to the page.
* It accepts an `XMLElement` (which should be of the `Anchor` type),
* an optional parameter `$prepend`, which when `true` will add this
* action before any existing actions.
*
* @since Symphony 2.3
* @see core.Widget#Anchor
* @param XMLElement $action
* An Anchor element to add to the top of the page.
* @param boolean $append
* If true, this will add the `$action` after existing actions, otherwise
* it will be added before existing actions. By default this is `true`,
* which will add the `$action` after current actions.
*/
public function insertAction(XMLElement $action, $append = true)
{
$actions = $this->Context->getChildrenByName('ul');
// Actions haven't be added yet, create the element
if (empty($actions)) {
$ul = new XMLElement('ul', NULL, array('class' => 'actions'));
$this->Context->appendChild($ul);
} else {
$ul = current($actions);
$this->Context->replaceChildAt(1, $ul);
}
$li = new XMLElement('li', $action);
if ($append) {
$ul->prependChild($li);
} else {
$ul->appendChild($li);
}
}
示例2: findEntries
private function findEntries(XMLElement $xml)
{
// check if xml has child elements
if (($elements = $xml->getChildren()) && is_array($elements)) {
// handle elements
foreach ($elements as $element_index => $element) {
// check if element is xml element
if ($element instanceof XMLElement) {
// check if element is entry
if ($element->getName() === 'entry') {
// process fields
$element = $this->processFields($element);
} else {
// find entries
$element = $this->findEntries($element);
}
// replace element
$xml->replaceChildAt($element_index, $element);
}
}
}
return $xml;
}