本文整理匯總了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;
}