使用C#在XML文件中使用Duplicatenode [英] Duplicatenode in an XML file using C#

查看:113
本文介绍了使用C#在XML文件中使用Duplicatenode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想复制带有所有子节点的nmodes,并将其附加到ExportedObjects节点中。其他notenode也是如此。复制Type Node的所有子节点并附加它



我尝试过:



...................

I want to duplicate nmodes with all its child node and append it inside ExportedObjects node. Same goes for other notenode. Copy all child node of Type Node and append it

What I have tried:

...................

推荐答案

您需要获取克隆元素并将其添加到您需要它的节点。它可以是您的根节点,外部OI节点或其他XML文档。但是你必须在某处拥有node.Add(clonedNode)。



另外,考虑使用XPath精确选择OI节点,这个LastChild.LastChild.LastChild创建结构依赖性和如果有人添加偶数< br />,您的代码将会中断在XML的末尾。



而是选择
You need to take cloned element and add it to the node where you need it to be. It can be your root node, your outer OI node or another XML document. But you have to have node.Add (clonedNode) somewhere.

Also, consider using XPath to select OI node precisely, this LastChild.LastChild.LastChild creates structural dependancy and your code will break if someone adds even <br /> at the end of your XML.

Instead, select
rootNode.SelectSingleNode("//ExportedObjects");

并从那里开始工作。


检查:< a href =http://www.codeproject.com/Questions/1129325/Copy-all-nodes-of-a-parent-and-append-it-in-the-pa#answer1>复制一个节点parent并将其附加到父节点中,用每个副本替换该属性 [ ^ ]


这篇关于使用C#在XML文件中使用Duplicatenode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆