Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- using System.Xml.Linq;
- XDocument xmlFile = XDocument.Load("books.xml");
- var query = from c in xmlFile.Elements("catalog").Elements("book")
- select c;
- foreach (XElement book in query)
- {
- book.Attribute("attr1").Value = "MyNewValue";
- }
- xmlFile.Save("books.xml");
Add Comment
Please, Sign In to add comment