本文整理匯總了PHP中DOMNode::appendElement方法的典型用法代碼示例。如果您正苦於以下問題:PHP DOMNode::appendElement方法的具體用法?PHP DOMNode::appendElement怎麽用?PHP DOMNode::appendElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DOMNode
的用法示例。
在下文中一共展示了DOMNode::appendElement方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: transferNode
/**
* @param \DOMNode|Element $node
* @param \DOMNode|Document|Element $target
*/
private function transferNode(\DOMNode $node, \DOMNode $target)
{
if ($node->namespaceURI === self::XMLNS_JSONX) {
if ($target instanceof Document) {
$normalizedName = $name = 'json:json';
} else {
$name = $node->getAttribute('name');
$normalizedName = QualifiedName::normalizeString($name, self::DEFAULT_QNAME);
}
$type = $node->localName;
$newNode = $target->appendElement($normalizedName);
if ($name !== $normalizedName && $name !== '') {
$newNode->setAttribute('json:name', $name);
}
switch ($type) {
case 'object':
if ($node('count(*) > 0')) {
foreach ($node('*') as $childNode) {
$this->transferNode($childNode, $newNode);
}
return;
}
break;
case 'array':
foreach ($node('*') as $childNode) {
$this->transferNode($childNode, $newNode);
}
break;
case 'string':
$newNode->append((string) $node);
return;
default:
$newNode->append((string) $node);
break;
}
$newNode->setAttribute('json:type', $type);
}
}