当前位置: 首页>>代码示例>>C#>>正文


C# XmlNode.InsertBefore方法代码示例

本文整理汇总了C#中System.Xml.XmlNode.InsertBefore方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNode.InsertBefore方法的具体用法?C# XmlNode.InsertBefore怎么用?C# XmlNode.InsertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlNode的用法示例。


在下文中一共展示了XmlNode.InsertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddDocumentNode

        public static void AddDocumentNode(XmlNode parent, ComponentRenderType outputType, string value)
        {
            XmlElement text = parent.OwnerDocument.CreateElement(UADataType.UAString.ToString());
            text.InnerText = value;
            text.SetAttribute(DecoratorTags.OutputDecorator, ComponentRenderType.Title.ToString());
            parent.InsertBefore(text, parent.FirstChild);

        }
开发者ID:BlueSkyStatistics,项目名称:BlueSkyRepository,代码行数:8,代码来源:XmlDocumentDecorator.cs

示例2: ExcelChartTitle

 internal ExcelChartTitle(XmlNamespaceManager nameSpaceManager, XmlNode node)
     : base(nameSpaceManager, node)
 {
     XmlNode topNode = node.SelectSingleNode("c:title", NameSpaceManager);
     if (topNode == null)
     {
         topNode = node.OwnerDocument.CreateElement("c", "title", ExcelPackage.schemaChart);
         node.InsertBefore(topNode, node.ChildNodes[0]);
         topNode.InnerXml = "<c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:r><a:t /></a:r></a:p></c:rich></c:tx><c:layout />";
     }
     TopNode = topNode;
 }
开发者ID:huoxudong125,项目名称:EPPlus,代码行数:12,代码来源:ExcelChartTitle.cs

示例3: ExcelChartTitle

 internal ExcelChartTitle(XmlNamespaceManager nameSpaceManager, XmlNode node) :
     base(nameSpaceManager, node)
 {
     XmlNode topNode = node.SelectSingleNode("c:title", NameSpaceManager);
     if (topNode == null)
     {
         topNode = node.OwnerDocument.CreateElement("c", "title", ExcelPackage.schemaChart);
         node.InsertBefore(topNode, node.ChildNodes[0]);
         topNode.InnerXml = "<c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr sz=\"1800\" b=\"0\" /></a:pPr><a:r><a:t /></a:r></a:p></c:rich></c:tx><c:layout /><c:overlay val=\"0\" />";
     }
     TopNode = topNode;
     SchemaNodeOrder = new string[] { "tx","bodyPr", "lstStyle", "layout", "overlay" };
 }
开发者ID:acinep,项目名称:epplus,代码行数:13,代码来源:ExcelChartTitle.cs

示例4: UpdateXmlNode

        private void UpdateXmlNode(XmlNode node, string collectionName, string itemName, string lcid, string description)
        {
            XmlNode refNode;
            if (collectionName == "Titles" && node.FirstChild != null)
            {
                //Title should allways be first elemnt
                refNode = node.FirstChild;
            }
            else
            {
                switch (node.Name)
                {
                    case "Area":
                        refNode = node.SelectSingleNode("Group");
                        break;

                    case "Group":
                        refNode = node.SelectSingleNode("SubArea");
                        break;

                    case "SubArea":
                        refNode = node.SelectSingleNode("Privilege");
                        break;

                    default:
                        throw new Exception("Unexpected node name");
                }
            }

            var labelsNode = node.SelectSingleNode(collectionName);
            if (labelsNode == null)
            {
                labelsNode = node.OwnerDocument.CreateElement(collectionName);
                if (refNode != null)
                {
                    node.InsertBefore(labelsNode, refNode);
                }
                else
                {
                    node.AppendChild(labelsNode);
                }
            }

            var labelNode = labelsNode.SelectSingleNode(string.Format(itemName + "[@LCID='{0}']", lcid));
            if (labelNode == null)
            {
                labelNode = node.OwnerDocument.CreateElement(itemName);
                labelsNode.AppendChild(labelNode);

                var languageAttr = node.OwnerDocument.CreateAttribute("LCID");
                languageAttr.Value = lcid;
                labelNode.Attributes.Append(languageAttr);
                var descriptionAttr = node.OwnerDocument.CreateAttribute(itemName);
                labelNode.Attributes.Append(descriptionAttr);
            }

            labelNode.Attributes[itemName].Value = description;
        }
开发者ID:NORENBUCH,项目名称:XrmToolBox,代码行数:58,代码来源:SiteMapTranslation.cs

示例5: InsertFirstChild

        // 插入新对象到儿子们的最前面
        public static XmlNode InsertFirstChild(XmlNode parent, XmlNode newChild)
        {
            XmlNode refChild = null;
            if (parent.ChildNodes.Count > 0)
                refChild = parent.ChildNodes[0];

            return parent.InsertBefore(newChild, refChild);
        }
开发者ID:renyh1013,项目名称:dp2weixin,代码行数:9,代码来源:DomUtil.cs

示例6: PossiblyRenameElementHack

        /// <summary>
        ///  Flex had been writing some 'text' elements in lift/lift-ranges files using the RelaxNg gramamr spec, but as a literal,
        /// not what the grammar was saying. This method fixes those, if needed.
        /// 
        /// There is not really good place to do that, so here is where it happens.
        /// </summary>
        private static XmlNode PossiblyRenameElementHack(XmlNode parent, XmlNode childNodeAsVariable)
        {
            if (childNodeAsVariable.NodeType != XmlNodeType.Element)
                return childNodeAsVariable;
            // Do nothing at all, if it isn't <element>.
            if (childNodeAsVariable.Name != "element")
                return childNodeAsVariable;

            var doc = childNodeAsVariable.OwnerDocument;
            var docRoot = doc.DocumentElement;
            if (docRoot.Name != "lift" && docRoot.Name != "lift-ranges")
                return childNodeAsVariable; // Skip data that isn't lift or lift-range

            var newElement = doc.CreateElement("text");
            while (childNodeAsVariable.HasChildNodes)
            {
                newElement.AppendChild(childNodeAsVariable.FirstChild);
            }

            // Removes bogus 'text' attribute, by ignoring it.

            parent.InsertBefore(newElement, childNodeAsVariable);
            parent.RemoveChild(childNodeAsVariable);
            childNodeAsVariable = newElement;

            return childNodeAsVariable;
        }
开发者ID:sillsdev,项目名称:chack,代码行数:33,代码来源:XmlMergeService.cs

示例7: InsertNewXmlNode

 protected override void InsertNewXmlNode(XmlNode parentElement, XmlNode newElement)
 {
     if (newElement.Name == "Package")
     {
         if (parentElement.FirstChild != null)
         {
             parentElement.InsertBefore(newElement, parentElement.FirstChild);
         }
         else
         {
             parentElement.AppendChild(newElement);
         }
     }
     else
     {
         base.InsertNewXmlNode(parentElement, newElement);
     }
 }
开发者ID:xwiz,项目名称:WixEdit,代码行数:18,代码来源:EditGlobalDataPanel.cs

示例8: ToVersion20

        /// <summary>Convert from old soil XML format to new soil XML format</summary>
        /// <param name="Node">The node to convert</param>
        private static void ToVersion20(XmlNode Node)
        {
            if (Node.Name.ToLower() == "soil")
            {
                // If there is a <Phosphorus> node then get rid of it. It is old and not used.
                XmlNode OldPhosphorusNode = XmlUtilities.FindByType(Node, "Phosphorus");
                if (OldPhosphorusNode != null)
                    Node.RemoveChild(OldPhosphorusNode);

                XmlNode ProfileNode = XmlUtilities.Find(Node, "profile");
                if (ProfileNode != null)
                {
                    XmlNode WaterNode = Node.AppendChild(Node.OwnerDocument.CreateElement("Water"));
                    XmlNode SoilWatNode = Node.AppendChild(Node.OwnerDocument.CreateElement("SoilWat"));
                    XmlNode SOMNode = Node.AppendChild(Node.OwnerDocument.CreateElement("SoilOrganicMatter"));
                    XmlNode LABNode = Node.AppendChild(Node.OwnerDocument.CreateElement("Lab"));

                    XmlNode CountryNode = AnnotateNode(Node, "Country", "", "");
                    Node.InsertBefore(CountryNode, Node.FirstChild);

                    AnnotateNode(Node, "State", "", "");
                    AnnotateNode(Node, "Region", "", "");
                    AnnotateNode(Node, "NearestTown", "", "Nearest town");
                    AnnotateNode(Node, "Site", "", "");
                    AnnotateNode(Node, "ApsoilNumber", "", "Apsoil number");
                    AnnotateNode(Node, "SoilType", "", "Classification");
                    AnnotateNode(Node, "Latitude", "", "Latitude (WGS84)");
                    AnnotateNode(Node, "Langitude", "", "Longitude (WGS84)");
                    AnnotateNode(Node, "LocationAccuracy", "", "Location accuracy");
                    AnnotateNode(Node, "NaturalVegetation", "", "Natural vegetation");
                    AnnotateNode(Node, "DataSource", "multiedit", "Data source");
                    AnnotateNode(Node, "Comment", "multiedit", "Comments");

                    XmlNode ConaNode = XmlUtilities.Find(Node, "CONA");
                    if (ConaNode != null)
                    {
                        XmlUtilities.SetValue(SoilWatNode, "SummerCona", ConaNode.InnerText);
                        XmlUtilities.SetValue(SoilWatNode, "WinterCona", ConaNode.InnerText);
                        Node.RemoveChild(ConaNode);
                        XmlNode UNode = XmlUtilities.Find(Node, "U");
                        if (UNode != null)
                        {
                            XmlUtilities.SetValue(SoilWatNode, "SummerU", UNode.InnerText);
                            XmlUtilities.SetValue(SoilWatNode, "WinterU", UNode.InnerText);
                            Node.RemoveChild(UNode);
                        }
                    }
                    else
                    {
                        MoveSoilNode(Node, "SummerCona", SoilWatNode);
                        MoveSoilNode(Node, "SummerU", SoilWatNode);
                        MoveSoilNode(Node, "SummerDate", SoilWatNode);
                        MoveSoilNode(Node, "WinterCona", SoilWatNode);
                        MoveSoilNode(Node, "WinterU", SoilWatNode);
                        MoveSoilNode(Node, "WinterDate", SoilWatNode);
                    }
                    if (XmlUtilities.Value(SoilWatNode, "SummerDate") == "")
                        XmlUtilities.SetValue(SoilWatNode, "SummerDate", "1-Nov");
                    if (XmlUtilities.Value(SoilWatNode, "WinterDate") == "")
                        XmlUtilities.SetValue(SoilWatNode, "WinterDate", "1-Apr");

                    MoveSoilNode(Node, "DiffusConst", SoilWatNode);
                    MoveSoilNode(Node, "DiffusSlope", SoilWatNode);
                    MoveSoilNode(Node, "SALB", SoilWatNode);
                    MoveSoilNode(Node, "CN2Bare", SoilWatNode);
                    MoveSoilNode(Node, "CNRed", SoilWatNode);
                    MoveSoilNode(Node, "CNCov", SoilWatNode);
                    MoveSoilNode(Node, "CNCanopyFact", SoilWatNode);
                    MoveSoilNode(Node, "DiffusConst", SoilWatNode);
                    MoveSoilNode(Node, "RootCN", SoilWatNode);
                    MoveSoilNode(Node, "RootWT", SoilWatNode);
                    MoveSoilNode(Node, "SoilCN", SoilWatNode);
                    MoveSoilNode(Node, "EnrACoeff", SoilWatNode);
                    MoveSoilNode(Node, "EnrBCoeff", SoilWatNode);
                    foreach (XmlNode LayerNode in XmlUtilities.ChildNodes(ProfileNode, "Layer"))
                    {
                        XmlNode WaterLayerNode = WaterNode.AppendChild(Node.OwnerDocument.CreateElement("Layer"));
                        XmlNode SoilWatLayerNode = SoilWatNode.AppendChild(Node.OwnerDocument.CreateElement("Layer"));
                        XmlNode SOMLayerNode = SOMNode.AppendChild(Node.OwnerDocument.CreateElement("Layer"));
                        XmlNode LABLayerNode = LABNode.AppendChild(Node.OwnerDocument.CreateElement("Layer"));

                        SetValue(WaterLayerNode, "Thickness", XmlUtilities.Value(LayerNode, "Thickness"), "mm");
                        SetValue(SoilWatLayerNode, "Thickness", XmlUtilities.Value(LayerNode, "Thickness"), "mm");
                        SetValue(SOMLayerNode, "Thickness", XmlUtilities.Value(LayerNode, "Thickness"), "mm");
                        SetValue(LABLayerNode, "Thickness", XmlUtilities.Value(LayerNode, "Thickness"), "mm");

                        SetValue(WaterLayerNode, "BD", XmlUtilities.Value(LayerNode, "BD"), "g/cc");
                        SetValue(WaterLayerNode, "AirDry", XmlUtilities.Value(LayerNode, "AirDry"), "mm/mm");
                        SetValue(WaterLayerNode, "LL15", XmlUtilities.Value(LayerNode, "LL15"), "mm/mm");
                        SetValue(WaterLayerNode, "DUL", XmlUtilities.Value(LayerNode, "DUL"), "mm/mm");
                        SetValue(WaterLayerNode, "SAT", XmlUtilities.Value(LayerNode, "SAT"), "mm/mm");
                        SetValue(WaterLayerNode, "KS", XmlUtilities.Value(LayerNode, "KS"), "mm/day");
                        foreach (XmlNode LLNode in XmlUtilities.ChildNodes(LayerNode, "ll"))
                        {
                            string CropName = XmlUtilities.NameAttr(LLNode);
                            XmlNode CropNode = XmlUtilities.Find(WaterNode, CropName);
                            if (CropNode == null)
                            {
//.........这里部分代码省略.........
开发者ID:rcichota,项目名称:APSIM.Shared,代码行数:101,代码来源:ConvertSoilNode.cs

示例9: RenameElement

        // From http://stackoverflow.com/questions/475293/change-the-node-names-in-an-xml-file-using-c-sharp .
        static XmlElement RenameElement(XmlNode parent, XmlNode child, string newName)
        {
            // get existing 'Content' node
//            XmlNode contentNode = parent.SelectSingleNode("Content");

            // create new (renamed) Content node
            XmlElement newNode = parent.OwnerDocument.CreateElement(newName);

            // [if needed] copy existing Content children
            newNode.InnerXml = child.InnerXml;
            foreach(XmlAttribute attr in child.Attributes)
                newNode.SetAttribute(attr.Name, attr.Value);

            // replace existing Content node with newly renamed Content node
            parent.InsertBefore(newNode, child);
            parent.RemoveChild(child);
            return newNode;
        }
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:19,代码来源:CodeStructure.cs

示例10: removeLinkto

        private void removeLinkto(XmlNode node)
        {
            if (node.NodeType == XmlNodeType.Element)
            {
                if (node.HasChildNodes)
                    foreach (XmlNode child in node.ChildNodes)
                        removeLinkto(child);

                Collection<string> attrsToBeRemoved = new Collection<string>();

                //look for linkto attributes and attributes with @linkto value
                foreach (XmlAttribute xattr in node.Attributes)
                {
                    if (xattr.Name.Equals("linkto"))//linkto attribute
                    {
                        XmlNode linktoNode = node.Attributes.GetNamedItem("linkto");

                        if (linktoNode != null)
                        {
                            string linksto = linktoNode.Value;
                            //node.Attributes.RemoveNamedItem("linkto");//cannot change foreach collection
                            attrsToBeRemoved.Add(xattr.Name);

                            XmlNode valueofNode = node.OwnerDocument.CreateElement("xsl", "value-of", "http://www.w3.org/1999/XSL/Transform");

                            XmlAttribute selectattr = node.OwnerDocument.CreateAttribute("select");
                            selectattr.Value = linksto;
                            valueofNode.Attributes.Append(selectattr);

                            XmlNode innerTextNode = node.SelectSingleNode("text()");
                            if (innerTextNode != null)
                                innerTextNode.InnerText = string.Empty;

                            node.AppendChild(valueofNode);

                            //generate tooltip -> would not work with SVG
                            /*XmlAttribute tooltipAttr = node.OwnerDocument.CreateAttribute("ToolTip");
                            tooltipAttr.Value = linksto;
                            if (node.Name.IndexOf('.') == -1)
                            {
                                node.Attributes.Append(tooltipAttr);
                            }
                            else if ((node.ParentNode != null) && (node.ParentNode.Name.IndexOf('.') == -1))
                            {
                                node.ParentNode.Attributes.Append(tooltipAttr);
                            }*/
                        }
                    }
                    else if (xattr.Value.StartsWith("@linkto"))
                    {
                        //linkto generates an attribute
                        attrsToBeRemoved.Add(xattr.Name);

                        string linkstoAttributeName = xattr.Name;
                        string linksto = xattr.Value.Substring(xattr.Value.IndexOf("=") + 1); //remove @linkto=, sample format is Fill="@linkto=Color|Green"
                        string linkstoAttributeValue;
                        string linkstoAttributeDefault;

                        if (linksto.Contains("|"))//"Color|Green"
                        {
                            linkstoAttributeDefault = linksto.Substring(linksto.IndexOf("|") + 1);
                            linkstoAttributeValue = linksto.Substring(0, linksto.IndexOf("|"));
                        }
                        else//"Color"
                        {
                            linkstoAttributeValue = linksto;
                            linkstoAttributeDefault = "";
                        }

                        //generate XSL code for the attribute
                        XmlNode attributeNode = node.OwnerDocument.CreateElement("xsl", "attribute", "http://www.w3.org/1999/XSL/Transform");
                        XmlAttribute attrName = node.OwnerDocument.CreateAttribute("name");
                        attrName.Value = linkstoAttributeName;
                        attributeNode.Attributes.Append(attrName);

                        XmlNode valueofNode = node.OwnerDocument.CreateElement("xsl", "value-of", "http://www.w3.org/1999/XSL/Transform");
                        XmlAttribute selectattr = node.OwnerDocument.CreateAttribute("select");
                        selectattr.Value = linkstoAttributeValue;
                        valueofNode.Attributes.Append(selectattr);
                        attributeNode.AppendChild(valueofNode);

                        node.InsertBefore(attributeNode, node.FirstChild);//XSL to append attribute to the parent node

                        //MessageBox.Show("Name: " + linkstoAttributeName + "\nValue: " + linkstoAttributeValue+ "\nDefault: "+linkstoAttributeDefault);

                    }
                }

                //remove previous attributes
                foreach (string sattr in attrsToBeRemoved)
                {
                    node.Attributes.RemoveNamedItem(sattr);
                }

                //clear collection
                attrsToBeRemoved.Clear();
            }
        }
开发者ID:imanavaz,项目名称:CONVErT,代码行数:98,代码来源:Skin.xaml.cs

示例11: InsertSorted

		public static void InsertSorted(XmlNode parent, XmlNode child, Comparison<XmlNode> comparer)
		{
			foreach(XmlNode node in parent.ChildNodes)
			{
				if (comparer(node, child) > 0)
				{
					parent.InsertBefore(child, node);
					return;
				}
			}
			parent.AppendChild(child);
		}
开发者ID:zcnet4,项目名称:lua-tilde,代码行数:12,代码来源:Project.cs

示例12: insertSequence

        public static void insertSequence(XmlElement element,
            XmlNode root)
        {
            string strTag = GetTag(element);
            if (strTag == "###")
            {
                // TODO: 注意插入前是否已经有了一个头标区,避免插入后变成两个
                root.InsertBefore(root.OwnerDocument.ImportNode(element, true), null);
                return;
            }

            // 寻找插入位置
            List<int> values = new List<int>(); // 累积每个比较结果数字
            int nInsertPos = -1;
            int i = 0;
            foreach (XmlNode current in root.ChildNodes)
            {
                if (current.NodeType != XmlNodeType.Element)
                {
                    i++;
                    continue;
                }
                XmlElement current_element = (XmlElement)current;
                string strCurrentTag = GetTag(current_element);

                int nBigThanCurrent = 0;   // 相当于node和当前对象相减

                nBigThanCurrent = string.Compare(strTag, strCurrentTag);
                if (nBigThanCurrent < 0)
                {
                    nInsertPos = i;
                    break;
                }
                if (nBigThanCurrent == 0)
                {
                    /*
                    if ((style & InsertSequenceStyle.PreferHead) != 0)
                    {
                        nInsertPos = i;
                        break;
                    }
                     * */
                }

                // 刚刚遇到过相等的一段,但在当前位置结束了相等 (或者开始变大,或者开始变小)
                if (nBigThanCurrent != 0 && values.Count > 0 && values[values.Count - 1] == 0)
                {
                        nInsertPos = i - 1;
                        break;
                }

                values.Add(nBigThanCurrent);
                i++;
            }

            if (nInsertPos == -1)
            {
                root.AppendChild(root.OwnerDocument.ImportNode(element, true));
                return;
            }

            root.InsertBefore(root.OwnerDocument.ImportNode(element, true), root.ChildNodes[nInsertPos]);
        }
开发者ID:paopaofeng,项目名称:dp2,代码行数:63,代码来源:AppBiblio.cs

示例13: MergePropertyAndGroup

 private static void MergePropertyAndGroup(XmlNode newParent, XmlNode mergingParent, string name)
 {
     Dictionary<string, XmlNode> propertyDict = new Dictionary<string, XmlNode>();
     Dictionary<string, XmlNode> groupDict = new Dictionary<string, XmlNode>();
     string value = "";
     //record the first property node where the Group node to insert before
     XmlNode firstProperty = null;
     foreach (XmlNode child in mergingParent.ChildNodes)
     {
         if (child.NodeType == XmlNodeType.Element)
         {
             value = child.Attributes[name].Value;
             try
             {
                 if (child.Name == "Property")
                 {
                     propertyDict.Add(value, child);
                 }
                 else
                     groupDict.Add(value, child);
             }
             catch
             {
                 throw new InvalidOperationException("Duplicate node with type\"" + child.Name + "name \"" + name + "\"=\"" + value + "\" found.");
             }
         }
     }
     foreach (XmlNode child in groupDict.Values)
     {
         bool duplicate = false;
         XmlNode old = null;
         foreach (XmlNode xn in newParent.ChildNodes)
         {
             if (xn.NodeType != XmlNodeType.Element)
                 continue;
             if (xn.Name == "Property" && firstProperty == null)
             {
                 firstProperty = xn;
                 continue;
             }
             if (xn.Name == "Group" && xn.Attributes[name].Value == child.Attributes[name].Value)
             {
                 duplicate = true;
                 old = xn;
                 break;
             }
         }
         if (duplicate)
         {
             MergePropertyAndGroup(old, child.CloneNode(true), name);
         }
         else
         {
             if(firstProperty == null)
                 newParent.AppendChild(child.CloneNode(true));
             else
                 newParent.InsertBefore(child.CloneNode(true), firstProperty);
         }
     }
     foreach (XmlNode child in propertyDict.Values)
     {
         bool duplicate = false;
         XmlNode old = null;
         foreach (XmlNode xn in newParent.ChildNodes)
         {
             if (xn.NodeType != XmlNodeType.Element || xn.Name != "Property")
                 continue;
             if (xn.Attributes[name].Value == child.Attributes[name].Value)
             {
                 duplicate = true;
                 old = xn;
                 break;
             }
         }
         if (duplicate)
         {
             newParent.ReplaceChild(child.CloneNode(true), old);
         }
         else
         {
             newParent.AppendChild(child.CloneNode(true));
         }
     }
     groupDict.Clear();
     propertyDict.Clear();
 }
开发者ID:LiuXiaotian,项目名称:ProtocolTestFramework,代码行数:86,代码来源:ConfigurationReader.cs

示例14: DeleteProject


//.........这里部分代码省略.........
                    if (bWarning == true) 
                    {
                        string strText = "系统发现,源代码文件 "
                            + strCodeFileName 
                            + " 除了被您即将删除的方案 "+
                            strProjectNamePath 
                            +" 使用外,还被下列方案引用:\r\n---\r\n";

                        for(int i=0;i<aFound.Count;i++)
                        {
                            strText += GetNodePathName((XmlNode)aFound[i]) + "\r\n";
                        }

                        strText += "---\r\n\r\n这意味着,如果删除这个源代码文件,上述方案将不能正常运行。\r\n\r\n请问,在删除方案" +strProjectNamePath+ "时,是否保留源代码文件 " + strCodeFileName + "?";

                        DialogResult msgResult = MessageBox.Show(//this,
                            strText,
                            "script",
                            MessageBoxButtons.YesNoCancel,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button1);

                        if (msgResult == DialogResult.Yes)
                            bDeleteCodeFile = false;
                        if (msgResult == DialogResult.Cancel)
                            return 2;	// cancel
                    }
                    else 
                    {
                        bDeleteCodeFile = false;	// 自动采用最保险的方式
                    }

                }
            }

            // 从Dom上删除节点
            parentXmlNode = nodeThis.ParentNode;
            parentXmlNode.RemoveChild(nodeThis);

            if (bDeleteCodeFile == true
                && strCodeFileName != "")
                File.Delete(strCodeFileName);

            m_bChanged = true;

            return 1;
        }
        */


        // 上下移动节点
        // return:
        //	0	not found
        //	1	found and moved
        //	2	cant move
        public int MoveNode(string strNodeNamePath,
            bool bUp,
            out XmlNode parentXmlNode)
        {
            parentXmlNode = null;

            XmlNode nodeThis = LocateAnyNode(strNodeNamePath);

            if (nodeThis == null)
                return 0;

            XmlNode nodeInsert = null;


            if (bUp == true)
            {
                nodeInsert = nodeThis.PreviousSibling;
                if (nodeInsert == null)
                    return 2;
            }
            else
            {
                nodeInsert = nodeThis.NextSibling;
                if (nodeInsert == null)
                    return 2;
            }

            // 从Dom上删除节点
            parentXmlNode = nodeThis.ParentNode;
            parentXmlNode.RemoveChild(nodeThis);

            // 插入到特定位置
            if (bUp == true)
            {
                parentXmlNode.InsertBefore(nodeThis, nodeInsert);
            }
            else
            {
                parentXmlNode.InsertAfter(nodeThis, nodeInsert);
            }

            m_bChanged = true;

            return 1;
        }
开发者ID:renyh1013,项目名称:dp2,代码行数:101,代码来源:ScriptManager.cs

示例15: XmlMerge

		/// <summary>
		/// Merges two XML subtrees.
		/// </summary>
		/// <param name="destination">The destination node.</param>
		/// <param name="source">The source node.</param>
		/// <param name="variables">Variables to be substituted in attribute values.</param>
		/// <param name="append"><B>True</B> to append <paramref name="source"/>'s children nodes to
		/// <paramref name="destination"/>'s children list, <B>false</B> to insert them as first children.</param>
		/// <returns><B>True</B> if successfully merged, <B>false</B> otherwise.</returns>
		private static bool XmlMerge(XmlNode destination, XmlNode source, Dictionary<string, string> variables, bool append/*, bool skipX86Extensions*/)
		{
			if (destination.NodeType != source.NodeType || destination.Name != source.Name) return false;

			// check attributes for equality
			bool equals = true;

			if (source.Attributes != null && destination.Attributes != null)
			{
				foreach (XmlAttribute src_attr in source.Attributes)
				{
					XmlAttribute dst_attr = destination.Attributes[src_attr.Name];
					if (dst_attr == null || dst_attr.Value != src_attr.Value)
					{
						equals = false;
						break;
					}
				}
			}

			if (!equals) return false;
			
			// iterate over children
			foreach (XmlNode src_child in source.ChildNodes)
			{
				if (src_child is XmlElement)
				{
                    /*if (skipX86Extensions)
                    {
                        var ass = src_child.Attributes["assembly"];

                        // skip assemblies with this key, because they are not compatible with x64 system
                        if (ass != null && ass.Value.Contains("PublicKeyToken=4ef6ed87c53048a3"))
                        {
                            continue;
                        }
                    }*/

					equals = false;

					foreach (XmlNode dst_child in destination.ChildNodes)
					{
                        if (XmlMerge(dst_child, src_child, variables, append/*, skipX86Extensions*/))
						{
							equals = true;
							break;
						}
					}

					if (!equals)
					{
						// we are adding the source subtree here
						if (append) destination.AppendChild(XmlAdopt(destination, src_child, variables));
						else destination.InsertBefore(XmlAdopt(destination, src_child, variables), destination.FirstChild);
					}
				}
			}

			return true;
		}
开发者ID:MpApQ,项目名称:Phalanger,代码行数:69,代码来源:MachineConfig.cs


注:本文中的System.Xml.XmlNode.InsertBefore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。