Use XDeclaration,XElement, XAttribute to create an XDocument : XDeclaration « XML LINQ « C# / C Sharp






Use XDeclaration,XElement, XAttribute to create an XDocument

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Reflection;
using System.Xml.Linq;

class Program {
    static void Main(string[] args) {
        XDocument xml = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
                                        new XElement("people",
                                            new XElement("idperson",
                                            new XAttribute("id", 1),
                                            new XAttribute("year", 2004),
                                            new XAttribute("salary", "100"))));

        System.IO.StringWriter sw = new System.IO.StringWriter();
        xml.Save(sw);
        Console.WriteLine(sw);
    }
}

 








Related examples in the same category

1.Creating a Declaration
2.Creating a Declaration and Setting the Document's Declaration Property to It