本文整理汇总了PHP中SimpleXMLElement::appendChild方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::appendChild方法的具体用法?PHP SimpleXMLElement::appendChild怎么用?PHP SimpleXMLElement::appendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::appendChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertPhpObjToDom
/**
* converts php-structure to DOM-object.
*
* @param array $arr php-structure
* @param SimpleXMLElement $node parent node where new element to attach
* @param DOMDocument $dom DOMDocument object
* @return SimpleXMLElement
*/
public static function convertPhpObjToDom($arr, $node, $dom)
{
if (is_array($arr)) {
/**
* If arr has integer keys, this php-array must be converted in
* xml-array representation (<array><item>..</item>..</array>)
*/
$arrayParam = array();
foreach ($arr as $k => $v) {
if (is_integer($k)) {
$arrayParam[] = $v;
}
}
if (0 < count($arrayParam)) {
$node->appendChild($arrayDom = $dom->createElement("array"));
foreach ($arrayParam as $key => $val) {
$new = $arrayDom->appendChild($dom->createElement('item'));
self::convertPhpObjToDom($val, $new, $dom);
}
} else {
foreach ($arr as $key => $val) {
$new = $node->appendChild($dom->createElement(self::encode($key)));
self::convertPhpObjToDom($val, $new, $dom);
}
}
} else {
$node->appendChild($dom->createTextNode(self::encode($arr)));
}
}
示例2: _convertLayoutHeadNode
protected function _convertLayoutHeadNode(SimpleXMLElement $sourceXml, SimpleXMLElement $targetXml)
{
foreach ($sourceXml->children() as $child) {
$path = $this->_env['ext_name'] . '::' . (string) $child;
break;
}
switch ((string) $sourceXml['method']) {
case 'addJs':
$targetNode = $targetXml->addChild('js');
$targetNode->addAttribute('class', $path);
break;
case 'addCss':
$targetNode = $targetXml->addChild('css');
$targetNode->addAttribute('src', $path);
break;
default:
$targetNode = $targetXml->appendChild($sourceXml->cloneNode(true));
}
}