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


C# XmlDocument.CloneNode方法代码示例

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


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

示例1: CloneComplexDocumentTrue

        public static void CloneComplexDocumentTrue()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(ComplexDocument);
            var cloned = xmlDocument.CloneNode(true);

            Assert.NotSame(xmlDocument.ChildNodes, cloned.ChildNodes);
            Assert.Equal(xmlDocument.NodeType, cloned.NodeType);
            Assert.Equal(xmlDocument.ChildNodes.Count, cloned.ChildNodes.Count);
            Assert.Equal(xmlDocument.LastChild.Value, cloned.LastChild.Value);

            // Test XmlNode.LastChild
            {
                for (var i = 0; i < xmlDocument.ChildNodes.Count; i++)
                {
                    if (xmlDocument.ChildNodes[i].LastChild == null)
                    {
                        Assert.Equal(xmlDocument.ChildNodes[i].LastChild, cloned.ChildNodes[i].LastChild);
                    }
                    else
                    {
                        Assert.Equal(xmlDocument.ChildNodes[i].LastChild.Value, cloned.ChildNodes[i].LastChild.Value);
                    }
                }
            }

            // Test XmlNode.NextSibling
            {
                var count = cloned.ChildNodes.Count;
                var previousNode = cloned.ChildNodes[0];

                for (var idx = 1; idx < count; idx++)
                {
                    var currentNode = cloned.ChildNodes[idx];
                    Assert.Equal(currentNode, previousNode.NextSibling);
                    previousNode = currentNode;
                }

                Assert.Null(previousNode.NextSibling);
            }

            // Test XmlNode.PreviousSibling
            {
                var count = cloned.ChildNodes.Count;
                var nextNode = cloned.ChildNodes[count - 1];

                for (var idx = count - 2; idx >= 0; idx--)
                {
                    var currentNode = cloned.ChildNodes[idx];
                    Assert.Equal(currentNode, nextNode.PreviousSibling);
                    nextNode = currentNode;
                }

                Assert.Null(nextNode.PreviousSibling);
            }

            // Test XmlNode.ParentNode
            CheckChildren(cloned);
        }
开发者ID:nandhanurrevanth,项目名称:corefx,代码行数:59,代码来源:CloneNodeTests.cs

示例2: Sign

        public XmlDocument Sign(
            XmlDocument message,
            String nonce,
            DateTime expiresAt
            )
        {
            if (message.DocumentElement == null)
                throw new ArgumentException("No root node in xdoc.");

            var copy = (XmlDocument)message.CloneNode(true);

            SignMessage(
                copy.DocumentElement,
                Convert.FromBase64String(nonce),
                expiresAt,
                new SharedSecret().From(_password)
            );

            return copy;
        }
开发者ID:ben-biddington,项目名称:Brick,代码行数:20,代码来源:XmlSigner.cs

示例3: CloneXmlDoc

        /// <summary>
        /// Make a copy of a XmlDocument
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <returns></returns>
        private static XmlDocument CloneXmlDoc(XmlDocument xmlDoc)
        {
            if (xmlDoc == null) return null;

            Log.Add(LogTypes.Debug, -1, "Cloning...");
            // Save copy of content
            var xmlCopy = (XmlDocument)xmlDoc.CloneNode(true);
            Log.Add(LogTypes.Debug, -1, "Cloning ended...");
            return xmlCopy;
        }
开发者ID:elrute,项目名称:Triphulcas,代码行数:15,代码来源:content.cs

示例4: CloneComplexDocumentTrueAndManipulate

        public static void CloneComplexDocumentTrueAndManipulate()
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<a>test</a>");
            var cloned = xmlDocument.CloneNode(true);

            cloned.FirstChild.FirstChild.Value = "replaced";

            Assert.Equal("test", xmlDocument.FirstChild.FirstChild.Value);
            Assert.Equal("replaced", cloned.FirstChild.FirstChild.Value);
        }
开发者ID:nandhanurrevanth,项目名称:corefx,代码行数:11,代码来源:CloneNodeTests.cs

示例5: CloneXmlDoc

 /// <summary>
 /// Make a copy of a XmlDocument
 /// </summary>
 /// <param name="xmlDoc"></param>
 /// <returns></returns>
 private static XmlDocument CloneXmlDoc(XmlDocument xmlDoc)
 {
     if (xmlDoc == null) return null;            
     
     // Save copy of content
     var xmlCopy = (XmlDocument)xmlDoc.CloneNode(true);            
     return xmlCopy;
 }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:13,代码来源:content.cs

示例6: CloneNode

		public void CloneNode ()
		{
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml ("<foo><bar /><baz hoge='fuga'>TEST Text</baz></foo>");
			XmlDocument doc2 = (XmlDocument)doc.CloneNode (false);
			AssertEquals ("ShallowCopy", 0, doc2.ChildNodes.Count);
			doc2 = (XmlDocument)doc.CloneNode (true);
			AssertEquals ("DeepCopy", "foo", doc2.DocumentElement.Name);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:XmlDocumentTests.cs

示例7: DeserializeElement

		protected override void DeserializeElement (XmlReader reader, bool serializeCollectionKey)
		{
			original = new XmlDocument ().ReadNode (reader);
			node = original.CloneNode (true);
		}
开发者ID:Xipas,项目名称:Symplified.Auth,代码行数:5,代码来源:SettingValueElement.cs


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