How to comment an XMLElement using C#?

c#, xml

Solution

To comment an xml node I would do it like this :

XmlComment DirCom = doc.CreateComment(XmlElementName.OuterXml);
doc.InsertAfter(DirCom, XmlElementName);    
doc.RemoveChild(XmlElementName)

Problem

My application reads values from an xml file which I write everytime when I execute the application. This is how I made comments of my lines: ``` XmlComment DirCom = doc.CreateComment("Comment") XmlElementName.AppendChild(DirCom); ``` And It works fine, But now I need to comment the XML element, And the above doesn't work. My final result should be like: ``` <!--<name>David</name>--> ``` using C# and the XML document library.

Original source