Replaces the child node oldChild with newChild node.
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='Computer' ISBN='1-111111-57-5'>" + "<title>C#</title>" + "</book>"); XmlNode root = doc.DocumentElement; XmlElement elem = doc.CreateElement("title"); elem.InnerText="The Handmaid's Tale"; root.ReplaceChild(elem, root.FirstChild); doc.Save(Console.Out); } }