C#: Adding CData Sections to an Existing Node using XmlDocument and XDocument to handle HTML code or other problematic characters

Jul 142009

There are situations where the data within nodes of Xml need to be handled due to special characters or html type tags. To handle that one must place data into CData sections. This artcle shows one how to do that in .Net using C# for both the XMLDocument as well as the XDocument.

The older technology is <code>XmlDocument</code> and the newer one introduced with Linq is <code>XDocument</code>. I personally find both bizarrely hard to use, but the easier one is <code>XDocument</code> overall, but if you have XPath queries the XmlDocument is a better choice.