如何更改XML属性 [英] How to change XML Attribute

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

问题描述

我怎样才能改变一个元素的属性在XML文件中,使用C#?

How can I change an attribute of an element in an XML file, using C#?

推荐答案

麦克;
      每次我需要修改我的工作是一个XML文档是这样的:

Mike; Everytime I need to modify an XML document I work it this way:

//Here is the variable with which you assign a new value to the attribute
string newValue = string.Empty;
XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(xmlFile);

XmlNode node = xmlDoc.SelectSingleNode("Root/Node/Element");
node.Attributes[0].Value = newValue;

xmlDoc.Save(xmlFile);

//xmlFile is the path of your file to be modified

我希望你觉得它有用

I hope you find it useful

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

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