Add the CData to XDocument in CSharp

Description

The following code shows how to add the CData to XDocument.

Example


using System;/*from ww w .j a  v a  2  s  .  co  m*/
using System.Linq;
using System.Xml;
using System.Xml.Linq;
public class MainClass{

   public static void Main(string[] args){   
      XDocument NewDoc = new XDocument(
            new XDeclaration("1.0", "utf-8", "yes"),
            new XElement("Root", "MyDoc"));  
      // Add the CData.
      NewDoc.Element("Root").Add(
            new XElement("CDataElement",
               new XCData("This is a CData Entry!")));

      Console.WriteLine(NewDoc);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style