當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SimpleXMLElement::insertNodeFirst方法代碼示例

本文整理匯總了PHP中SimpleXMLElement::insertNodeFirst方法的典型用法代碼示例。如果您正苦於以下問題:PHP SimpleXMLElement::insertNodeFirst方法的具體用法?PHP SimpleXMLElement::insertNodeFirst怎麽用?PHP SimpleXMLElement::insertNodeFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleXMLElement的用法示例。


在下文中一共展示了SimpleXMLElement::insertNodeFirst方法的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);
}
開發者ID:Sinepower,項目名稱:scripts-libraries,代碼行數:92,代碼來源:update_comps_to_cmplib_file.php


注:本文中的SimpleXMLElement::insertNodeFirst方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。