Add a comment to XDocument

image_pdfimage_print
   
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;


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 a comment.
      NewDoc.AddFirst(new XComment("This is a comment."));

      // Add another comment.
      NewDoc.Element("Root").Add(new XComment("This is another comment."));

      // Add a third comment.
      NewDoc.Add(new XComment("This is the third comment."));

      // Add some text.
      NewDoc.Element("Root").Add(new XText("This is some text."));
   }
}

   
     


This entry was posted in XML LINQ. Bookmark the permalink.