本文整理汇总了PHP中SimpleXMLElement::insertNodeAfterSpecifiedNode方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::insertNodeAfterSpecifiedNode方法的具体用法?PHP SimpleXMLElement::insertNodeAfterSpecifiedNode怎么用?PHP SimpleXMLElement::insertNodeAfterSpecifiedNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::insertNodeAfterSpecifiedNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UCTCF_AddItemDeclarationToCmpLib
function UCTCF_AddItemDeclarationToCmpLib(&$CACFconstants, &$UCTCFconstants, &$CmpLib, &$itemListById, &$itemListByName, $itemType, SimpleXMLElement &$newXmlNode, SimpleXMLElement &$parentXmlNode, $newItemName, $newItemId)
{
// echo "Hello from UCTCF_AddItemDeclarationToCmpLib()\n";
// echo "In UCTCF_AddItemDeclarationToCmpLib(), newItemName is \"$newItemName\", newItemId is \"$newItemId\", itemType is \"$itemType\".\n";
// echo "In UCTCF_AddItemDeclarationToCmpLib(), itemListById is:\n";
// print_r($itemListById);
/* Add new item to $itemListById array. */
if ($itemType == "TModelLink") {
$itemListById[$newItemId] = array("HRID" => $newItemName);
} else {
$itemListById[$newItemId] = $newItemName;
}
// echo "In UCTCF_AddItemDeclarationToCmpLib(), after adding, itemListById is now:\n";
// print_r($itemListById);
/* Choose a special comparison function when dealing with TModelLink. */
if ($itemType == "TModelLink") {
$compareFunc = "UCTCF_CompareByHRID";
} else {
$compareFunc = "strcasecmp";
}
/* Sort $itemListById array using non-case-sensitive sort. */
/* Note: Here we are using uasort() (with strcasecmp() as comparison func) to try to emulate what Altium does with ordering CmpLib href id references. */
$rc = uasort($itemListById, $compareFunc);
if ($rc == FALSE) {
my_die("uasort() failed!");
}
/** Insert new XML node into parent XML tag. **/
/* State the beginning of the xpath query. */
$xpathQuery = "/TComponentSet";
/* Construct the xpath prefix corresponding to our different item types. */
if ($itemType == "TRequiredParameter") {
$xpathQuery = $xpathQuery . "/RequiredParameters/TRequiredParameter";
} else {
if ($itemType == "TRequiredModel") {
$xpathQuery = $xpathQuery . "/RequiredModels/TRequiredModel";
} else {
if ($itemType == "TModelLink") {
$xpathQuery = $xpathQuery . "/ModelLinks/TModelLink";
} else {
my_die("Unsupported itemType \"{$itemType}\"!");
}
}
}
/* Flag that we have not yet seen a valid node. */
$insertAfter = false;
/* Loop over all item names. */
foreach ($itemListById as $id => $itemName) {
/* Special handling for dealing with TModelLink. */
if ($itemType == "TModelLink") {
$itemName = (string) $itemListById[$id]["HRID"];
}
// echo "In UCTCF_AddItemDeclarationToCmpLib(), id is $id, itemName is $itemName.\n";
/* See if this user parameter name already exists. */
if (isset($itemListByName[$itemName])) {
/* Flag that we now have a valid insertAfter node for future reference. */
$insertAfter = $itemName;
} else {
echo "Need to insert item name \"{$itemName}\".\n";
/* If we have already seen a valid XML node, then we can proceed to do the insert. */
if (!is_bool($insertAfter)) {
/** Get the XML node corresponding to the itemName stored in $insertAfter. **/
/* Finish constructing xpath query. */
$xpathQuery = $xpathQuery . "[HRID=\"{$insertAfter}\"]";
// echo "xpathQuery is \"$xpathQuery\".\n";
/* Run the xpath query to get the TRequiredParameter node in question. */
UCTCF_GetXmlNodeFromXpathQuery($CmpLib, $xpathQuery, $resultNode);
$insertAfterNode =& $resultNode;
// echo "insertAfterNode is:\n";
// print_r($insertAfterNode);
echo "Attempting to do simplexml_insert_after() operation!\n";
$parentXmlNode->insertNodeAfterSpecifiedNode($newXmlNode, $insertAfterNode);
} else {
// echo "Attempting to insert new first node!\n";
$parentXmlNode->insertNodeFirst($newXmlNode);
}
/* endelse */
}
/* endelse */
}
/* end foreach */
// echo "parent node is now:\n";
// print_r($parentXmlNode);
// echo "var dump of parent node:\n";
// var_dump($parentXmlNode);
// echo "In UCTCF_AddItemDeclarationToCmpLib(), itemListByName is:\n";
// print_r($itemListByName);
/* Add entry for new item to $itemListByName array. */
$itemListByName[$newItemName] = array();
$itemListByName[$newItemName]['id'] = $newItemId;
// echo "In UCTCF_AddItemDeclarationToCmpLib(), after adding, itemListByName is now:\n";
// print_r($itemListByName);
}