Set the value of a child element, adds a child element, or removes a child element in CSharp
Description
The following code shows how to set the value of a child element, adds a child element, or removes a child element.
Example
using System;/* w w w .ja va 2 s.c o m*/
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);
}
}