如何使用linqtoxml在xml文件中添加节点 [英] how to add a node in xml file using linqtoxml

查看:84
本文介绍了如何使用linqtoxml在xml文件中添加节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xml文件,如下所示:

< A>
< b id ="1">
</b>
< c id ="2">
</c>
</A>

我有两个文本框,在其中输入要添加新节点的根节点的ID.
如果我想在< b>中添加一个新节点,然后我在第一个文本框(b的ID)中输入"1",然后在其他文本框中输入新的节点名称,当我单击按钮时,将在根节点ID处将新节点添加到我的xml中.
请帮助我.
我正在使用Linq到XML.

I have a Xml file Like this:

<A>
<b id="1">
</b>
<c id="2">
</c>
</A>

I have two text box in which i enter a id of a root node where new node is added.
if I want to add a new node in <b> then i enter "1" in first textbox (ID of b) then in other text box I enter new node name, when i click on button then a new node will added to my xml at a root node id.
Please help me in this.
I m using Linq to XML.

推荐答案

请参阅此内容,

http://msdn.microsoft.com/en-us/library/system. xml.linq.xdocument.aspx [ ^ ]
Refer this,

http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx[^]


也请参阅此线程

> http://stackoverflow.com/questions/331502/linq-to-xml-update-alter-the-nodes-of-an-xml-document [
Please see this thread also

http://stackoverflow.com/questions/331502/linq-to-xml-update-alter-the-nodes-of-an-xml-document[^]


这篇关于如何使用linqtoxml在xml文件中添加节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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