Replace this node with the specified content in CSharp
Description
The following code shows how to replace this node with the specified content.
Example
//from w w w . ja va 2s. co m
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass{
public static void Main(){
XElement xmlTree = new XElement("Root",
new XElement("A1", "A1 content"),
new XElement("A2", "A2 content"),
new XElement("A3", "A3 content"),
new XElement("A4", "A4 content"),
new XElement("A5", "A5 content")
);
XElement child3 = xmlTree.Element("A3");
child3.ReplaceWith(
new XElement("NewA", "new content")
);
Console.WriteLine(xmlTree);
}
}