Create XDocument with XDeclaration and XElement in CSharp

Description

The following code shows how to create XDocument with XDeclaration and XElement.

Example


//from w  w  w  .jav  a2 s . c  om
using System;
using System.Linq;
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"));
      Console.WriteLine(NewDoc);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style