Mega Code Archive

 
Categories / C# / XML LINQ
 

XElement SetAttributeValue sets the value of an attribute, adds an attribute, or removes an attribute

using System; using System.IO; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){         XElement root = new XElement("Root");                  root.SetAttributeValue("Att1", 1);         root.SetAttributeValue("Att2", 2);         root.SetAttributeValue("Att3", 3);         Console.WriteLine(root);                  root.SetAttributeValue("Att2", 22);         Console.WriteLine(root);                  root.SetAttributeValue("Att3", null);         Console.WriteLine(root);     } }