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