How to change the XML attribute


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

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();


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


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

I hope you find it useful