Mega Code Archive

 
Categories / C# / XML LINQ
 

XElement SetElementValue sets the value of a child element, adds a child element, or removes a child element

using System; 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.SetElementValue("Ele1", 1);         root.SetElementValue("Ele2", 2);         root.SetElementValue("Ele3", 3);         Console.WriteLine(root);                  root.SetElementValue("Ele2", 22);         Console.WriteLine(root);                  root.SetElementValue("Ele3", null);         Console.WriteLine(root);    } }