Mega Code Archive

 
Categories / C# Book / 05 LINQ XML
 

0536 Replace an Element

using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; class Program { static void Main() { XElement items = XElement.Parse("<items><one/><two/><three/></items>"); items.FirstNode.ReplaceWith(new XComment("One was here")); Console.WriteLine(items); } } The output: <items><!--One was here--><two /><three /></items>