本文整理汇总了PHP中DOMNode::AddChildNode方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::AddChildNode方法的具体用法?PHP DOMNode::AddChildNode怎么用?PHP DOMNode::AddChildNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::AddChildNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MergeInto
/**
* Merge the current node into the given container
*
* @param DOMNode $oContainer An element or a document
* @param string $sSearchId The id to consider (could be blank)
* @param bool $bMustExist Throw an exception if the node must already be found (and not marked as deleted!)
*/
public function MergeInto($oContainer, $sSearchId, $bMustExist)
{
$oTargetNode = $oContainer->_FindChildNode($this, $sSearchId);
if ($oTargetNode) {
if ($oTargetNode->getAttribute('_alteration') == 'removed') {
if ($bMustExist) {
throw new Exception(MFDocument::GetItopNodePath($this) . ' at line ' . $this->getLineNo() . ": could not be found (marked as deleted)");
}
// Beware: ImportNode(xxx, false) DOES NOT copy the node's attribute on *some* PHP versions (<5.2.17)
// So use this workaround to import a node and its attributes on *any* PHP version
$oTargetNode = $oContainer->ownerDocument->ImportNode($this->cloneNode(false), true);
$oContainer->AddChildNode($oTargetNode);
}
} else {
if ($bMustExist) {
echo "Dumping parent node<br/>\n";
$oContainer->Dump();
throw new Exception(MFDocument::GetItopNodePath($this) . ' at line ' . $this->getLineNo() . ": could not be found");
}
// Beware: ImportNode(xxx, false) DOES NOT copy the node's attribute on *some* PHP versions (<5.2.17)
// So use this workaround to import a node and its attributes on *any* PHP version
$oTargetNode = $oContainer->ownerDocument->ImportNode($this->cloneNode(false), true);
$oContainer->AddChildNode($oTargetNode);
}
return $oTargetNode;
}
示例2: MergeInto
/**
* Merge the current node into the given container
*
* @param DOMNode $oContainer An element or a document
* @param string $sSearchId The id to consider (could be blank)
* @param bool $bMustExist Throw an exception if the node must already be found (and not marked as deleted!)
*/
public function MergeInto($oContainer, $sSearchId, $bMustExist)
{
$oTargetNode = $oContainer->_FindChildNode($this, $sSearchId);
if ($oTargetNode) {
if ($oTargetNode->getAttribute('_alteration') == 'removed') {
if ($bMustExist) {
throw new Exception("found mandatory node {$this->tagName}(id:{$sSearchId}) marked as deleted in " . $oContainer->getNodePath());
}
// Beware: ImportNode(xxx, false) DOES NOT copy the node's attribute on *some* PHP versions (<5.2.17)
// So use this workaround to import a node and its attributes on *any* PHP version
$oTargetNode = $oContainer->ownerDocument->ImportNode($this->cloneNode(false), true);
$oContainer->AddChildNode($oTargetNode);
}
} else {
if ($bMustExist) {
echo "Dumping parent node<br/>\n";
$oContainer->Dump();
throw new Exception("could not find {$this->tagName}(id:{$sSearchId}) in " . $oContainer->getNodePath());
}
// Beware: ImportNode(xxx, false) DOES NOT copy the node's attribute on *some* PHP versions (<5.2.17)
// So use this workaround to import a node and its attributes on *any* PHP version
$oTargetNode = $oContainer->ownerDocument->ImportNode($this->cloneNode(false), true);
$oContainer->AddChildNode($oTargetNode);
}
return $oTargetNode;
}