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


C# XmlNode.GetEnumerator方法代码示例

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


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

示例1: NodeTypesThatCantHaveChildren

		public void NodeTypesThatCantHaveChildren ()
		{
			document.LoadXml ("<foo>bar</foo>");
			documentElement = document.DocumentElement;
			node = documentElement.FirstChild;
			Assert.AreEqual (node.NodeType, XmlNodeType.Text, "Expected a text node.");
			Assert.AreEqual (node.HasChildNodes, false, "Shouldn't have children.");
			Assert.AreEqual (node.ChildNodes.Count, 0, "Should be empty node list.");
			Assert.AreEqual (node.GetEnumerator().MoveNext(), false, "Should be empty node list.");
		}
开发者ID:nobled,项目名称:mono,代码行数:10,代码来源:XmlNodeListTests.cs

示例2: SelectNodes

		/// <summary>
		/// Selects child nodes from a parent node satisfying the xpath
		/// </summary>
		/// <param name="xmlNode"></param>
		/// <param name="xpath"></param>
		/// <returns></returns>
		public static XmlNodeList SelectNodes (XmlNode xmlNode, string xpath)
		{

			XmlNode retXmlNode = xmlNode.Clone();
			retXmlNode.RemoveAll();
	
			IEnumerator iEnumerator = xmlNode.GetEnumerator();
			
			while (iEnumerator.MoveNext())
			{	
				XmlNode childXmlNode = (XmlNode)iEnumerator.Current;
				if (childXmlNode.LocalName.ToString() == xpath)
				{
					retXmlNode.AppendChild(childXmlNode.CloneNode(true));
				}
			}
		
			XmlNodeList retXmlNodeList = retXmlNode.ChildNodes;
			return retXmlNodeList; 
			
		}
开发者ID:JeffreyZksun,项目名称:gpstranslator,代码行数:27,代码来源:XPath.cs

示例3: FromXmlNode

            /// <summary>
            /// Adds all the images that can be found in the XmlNode
            /// </summary>
            /// <param name="node">the XmlNode to search through</param>
            public void FromXmlNode(XmlNode node) {
                IEnumerator ienumImages = node.GetEnumerator();
                while (ienumImages.MoveNext()) {
                    XmlNode imageNode = (XmlNode)ienumImages.Current;

                    switch (imageNode.Name) {
                        case "fanart":
                            Fanart.Add(new GameImage(imageNode.FirstChild));
                            break;
                        case "banner":
                            Banners.Add(new GameImage(imageNode));
                            break;
                        case "screenshot":
                            Screenshots.Add(new GameImage(imageNode.FirstChild));
                            break;
                        case "boxart":
                            if (imageNode.Attributes.GetNamedItem("side").InnerText == "front") {
                                BoxartFront = new GameImage(imageNode);
                            }
                            else {
                                BoxartBack = new GameImage(imageNode);
                            }

                            break;
                    }
                }
            }
开发者ID:stavrossk,项目名称:Windows_Game_Metadata_Retriever_for_.NET,代码行数:31,代码来源:Game.cs

示例4: FromXmlNode

            /// <summary>
            /// Adds all the images that can be found in the XmlNode
            /// </summary>
            /// <param name="node">the XmlNode to search through</param>
            public void FromXmlNode(XmlNode node)
            {
                IEnumerator ienumImages = node.GetEnumerator();
                while (ienumImages.MoveNext()) {
                    XmlNode imageNode = (XmlNode)ienumImages.Current;

                    switch (imageNode.Name) {
                        case "fanart":
                            Fanart.Add(new PlatformImage(imageNode.FirstChild));
                            break;
                        case "banner":
                            Banners.Add(new PlatformImage(imageNode));
                            break;
                        case "boxart":
                            Boxart = new PlatformImage(imageNode);
                            break;
                        case "consoleart":
                            ConsoleArt = imageNode.InnerText;
                            break;
                        case "controllerart":
                            ControllerArt = imageNode.InnerText;
                            break;
                    }
                }
            }
开发者ID:Blizz9,项目名称:FanCut,代码行数:29,代码来源:Platform.cs

示例5: CreateTree

        private void CreateTree(XmlNode node, TreeNode rootNode)
        {
            Program.AssertOnEventThread();

            if (node.NodeType == XmlNodeType.Text)
                rootNode.Text = node.Value;
            else
            {
                if (node.Name == "SPECIAL_XS_ENCODED_ELEMENT")
                    rootNode.Text = node.Attributes["name"].Value;
                else
                    rootNode.Text = node.Name;
            }
            IEnumerator ienum = node.GetEnumerator();
            while (ienum.MoveNext())
            {
                XmlNode current = (XmlNode)ienum.Current;
                TreeNode currentNode = new TreeNode();
                CreateTree(current, currentNode);
                rootNode.Nodes.Add(currentNode);
            }
        }
开发者ID:robertbreker,项目名称:xenadmin,代码行数:22,代码来源:DockerDetailsPage.cs

示例6: FindIds

        /*
         * Goes through the map and sets the colours up
         */
        private void FindIds(XmlNode root)
        {
            IEnumerator ienum = root.GetEnumerator();
            while (ienum.MoveNext()) {
                XmlNode node = (XmlNode)ienum.Current;
                XmlAttributeCollection attributes = node.Attributes;
                int index = -1;
                if(attributes != null) {
                    foreach (XmlAttribute attribute in attributes) {
                        if(attribute.Name == "id") {
                            if(lookUp.ContainsKey(attribute.Value)) {
                                index = lookUp[attribute.Value];
                            } else if (attribute.Value.Equals("MI-") || attribute.Value.Equals("SP-")) {
                                index = lookUp["MI"];
                            }
                        }
                    }

                    if(index != -1) {
                        foreach (XmlAttribute attribute in attributes) {
                            if (attribute.Name == "style") {
                                attribute.Value = newColours[result[index]];
                            }
                        }
                    }
                }
                if(node.HasChildNodes) {
                    FindIds(node);
                }
            }
        }
开发者ID:ThRM,项目名称:BackOnTheWeb,代码行数:34,代码来源:Program.cs

示例7: CompareNodes

        private static bool CompareNodes(XmlNode node1, XmlNode node2)
        {
            //compare properties
            if (node1.Attributes == null || node2.Attributes == null)
            {
                bool nullAttributes = (node1.Attributes == null && node2.Attributes == null);
                if (!nullAttributes)
                {
                    return false;
                }
            }
            else
            {
                if (node1.Attributes.Count != node2.Attributes.Count)
                {
                    Console.WriteLine("Attributes count: " + node1.Attributes.Count + "!=" + node2.Attributes.Count);
                    Console.WriteLine(node1.ParentNode.InnerXml);
                    Console.WriteLine(node2.ParentNode.InnerXml);
                    return false;
                }
            }
            if (node1.ChildNodes.Count != node2.ChildNodes.Count)
            {
                Console.WriteLine("Child nodes count: " + node1.ChildNodes.Count + " !=" + node2.ChildNodes.Count);
                return false;
            }

            if (node1.Name != node2.Name)
            {
                Console.WriteLine("Nodes Name: " + node1.Name + "!=" + node2.Name);
                return false;
            }

            if (node1.NodeType != node2.NodeType)
            {
                Console.WriteLine("Nodes Type: " + node1.NodeType + "!=" + node2.NodeType);
                return false;
            }

            //the content may have extra spaces or new lines

            string value1 = ("" + node1.Value).Trim().Replace(Environment.NewLine, "");
            string value2 = ("" + node2.Value).Trim().Replace(Environment.NewLine, "");

            //replace consecutive whitespaces with one space
            Regex whiteSpaces = new Regex("\\s+", RegexOptions.Singleline | RegexOptions.Multiline);
            value1 = whiteSpaces.Replace(value1, " ");
            value2 = whiteSpaces.Replace(value2, " ");

            if (value1 != value2)
            {
                Console.WriteLine("Nodes value: " + node1.Value + "!=" + node2.Value);
                return false;
            }

            //compare attributes
            XmlAttribute attribute;
            if (node1.Attributes != null && node2.Attributes != null)
            {
                foreach (XmlAttribute attr in node1.Attributes)
                {
                    attribute = node2.Attributes[attr.Name];
                    if (attribute == null)
                    {
                        Console.WriteLine("Null attribute: " + attr.Name);
                        return false;
                    }
                    if (attribute.Value != attr.Value)
                    {
                        Console.WriteLine("Attribute values: " + attribute.Value + "!=" + attr.Value);
                        return false;
                    }
                }
            }
            //compare child nodes
            IEnumerator enumerator1 = node1.GetEnumerator();
            IEnumerator enumerator2 = node2.GetEnumerator();
            bool childrenOK = true;
            while (enumerator1.MoveNext() && enumerator2.MoveNext())
            {
                childrenOK = CompareNodes((XmlNode)enumerator1.Current, (XmlNode)enumerator2.Current);
                if (!childrenOK)
                {
                    return false;
                }
            }

            //same properties, same attributes, same child nodes
            return true;
        }
开发者ID:xwiki-contrib,项目名称:xwiki-office,代码行数:90,代码来源:XmlDocComparator.cs


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