如何将XmlNode移到父级 [英] how to move XmlNode to parent level

查看:77
本文介绍了如何将XmlNode移到父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本paltform是C#winform,现在我需要编辑一个xml文件.
我想将xmlnode移到他的父级,就像下面将B移到A的顶部一样:
A
|
X-- |
| --B
|
C

但我尝试使用"A.ParentNode.InsertBefore(B,A);",但失败了.
而且我曾尝试使用克隆"或"AppendChild"到A.parent,然后"InterBefore"到A,但都失败了...


正确的方法是什么?还是在同一xmldocument中移动不同级别的xlmnode有一些限制?

The script paltform is C# winform,now i need edit a xml file.
i want move a xmlnode to his parent level,like below move B to the top of A:
A
|
X--|
|--B
|
C

but i try as "A.ParentNode.InsertBefore(B, A);", but failed.
And i had try to use "Clone" or "AppendChild" to A.parent then "InterBefore" to A, but all failed...


Whats the correct way? or there are some limits on differen level xlmnode moving within same xmldocument?

推荐答案

尝试以下操作:

将B节点克隆到新的XMLNode中.
卸下旧的(B).
然后将新的插入到所需的前面.
try the following:

Clone the B node in a new XMLNode.
Remove the old one(B).
Then insert the new one, before the desired one.


这篇关于如何将XmlNode移到父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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