更新xml文件中的属性 [英] Update an attribute in xml file

查看:74
本文介绍了更新xml文件中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有一个像这样的xml文件

Hi all
i have an xml file like that

<employee Id="5" EmpName="emp" Email="x@y.c" DeptId="3" ChatStatus="0" />


我需要根据employeeId将ChatStatus属性更新为"1".
有人可以帮我吗?

谢谢


I need to update ChatStatus attribute to be "1" according to employeeId.
Can Any One help me please?

Thanks

推荐答案

尝试一下
XmlDocument doc = new XmlDocument();
doc.Load("filename.xml");
XmlNodeList nodelist = doc.SelectNodes("employee");
if (nodelist[0].Attributes["Id"].Value == "5")
  {
     nodelist[0].Attributes["ChatStatus"].Value = "1";
     doc.Save("filename.xml");
  }



如果需要,可以更新第一个节点.



This will update the first node,if you want you can loop through the nodes.


^ ]


这篇关于更新xml文件中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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