如何在xml中添加Child元素 [英] How to add the Child elements in xml

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

问题描述

大家好,



我正在使用xml



当我添加新的贴纸时总是更换第1条记录它不接受第2条记录



我的代码是



hi all,

I am working on xml

when I add new recoard always replacing 1st record it''s not accepting 2nd.. records

my code is

if (File.Exists(path))
            {
                XElement xml = new XElement("Users", new XElement("User", new XElement("UserName", txtUserName.Text),
                    new XElement("Password", txtpassword.Text), new XElement("Role", Role)));
                xml.Save(path);
                MessageBox.Show("Saved");
            }





结果是



result is

//this is result
<Users>
  <User>
    <UserName>admin</UserName>
    <Password>admin</Password>
    <Role>Admin</Role>
  </User>
</Users>
//I want below result
<Users>
  <User>
    <UserName>admin</UserName>
    <Password>admin</Password>
    <Role>Admin</Role>
  </User>
<User>
    <UserName>test</UserName>
    <Password>test</Password>
    <Role>User</Role>
  </User>
</Users>

推荐答案

请查看以下链接。



http://www.bassicsoftware.com/ popup.aspx?b_id = 161 [ ^ ]



问候,

Manoj
Please look into the below link.

http://www.bassicsoftware.com/popup.aspx?b_id=161[^]

Regards,
Manoj


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

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