本文整理汇总了PHP中XMLElement::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLElement::getChildren方法的具体用法?PHP XMLElement::getChildren怎么用?PHP XMLElement::getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::getChildren方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processFields
private function processFields(XMLElement $xml)
{
// check if xml has child elements
if (($elements = $xml->getChildren()) && is_array($elements)) {
// handle elements
foreach ($elements as $element_index => $element) {
// get element handle
$element_handle = $element->getName();
// check if element handle is multilingual
if (preg_match('/-([a-z]{2})$/', $element_handle, $match)) {
// check if language is supported
if (in_array($match[1], self::$languages)) {
// remove language segment from element handle
$element_handle = preg_replace('/-' . $match[1] . '$/', '', $element_handle);
$element_mode = $element->getAttribute('mode');
// set new name and language
$element->setName($element_handle);
$element->setAttribute('lang', $match[1]);
$element->setAttribute('translated', 'yes');
// store element
$multilingual_elements[$element_handle . ($element_mode ? ':' . $element_mode : '')][$match[1]] = $element;
// remove element
$xml->removeChildAt($element_index);
}
}
}
// check for stored multilingual elements
if (is_array($multilingual_elements)) {
// handle multilingual elements
foreach ($multilingual_elements as $element_handle => $element) {
// handle languages
foreach (self::$languages as $language) {
// check if element exists for each language
if (!isset($element[$language]) || !(str_replace('<![CDATA[]]>', '', trim($element[$language]->getValue())) || $element[$language]->getNumberOfChildren())) {
// fallback to default language if missing or empty
if (isset($element[self::$languages[0]])) {
$element[$language] = clone $element[self::$languages[0]];
$element[$language]->setAttribute('lang', $language);
$element[$language]->setAttribute('translated', 'no');
}
}
}
// readd elements
$xml->appendChildArray($element);
}
}
}
return $xml;
}
示例2: getChildrenWithClass
private function getChildrenWithClass(XMLElement &$rootElement, $className, $tagName = null)
{
if ($rootElement == null) {
return null;
}
// contains the right css class and the right node name (if any)
// TODO: Use word bondaries instead of strpos
if ((!$className || strpos($rootElement->getAttribute('class'), $className) > -1) && (!$tagName || $rootElement->getName() == $tagName)) {
return $rootElement;
}
// recursive search in child elements
foreach ($rootElement->getChildren() as $key => $child) {
if (!$child instanceof XMLElement) {
continue;
}
$res = $this->getChildrenWithClass($child, $className, $tagName);
if ($res != null) {
return $res;
}
}
return null;
}