Linq To Xml Constructors : XAttribute « XML LINQ « C# / CSharp Tutorial






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

    class Program
    {
        static void Main(string[] args)
        {
            XDocument xdoc = new XDocument(
                new XElement("customers",
                    new XElement("customer",
                        new XAttribute("ID", "A"),
                        new XAttribute("City", "B"),
                        new XAttribute("Region", "C"),
                        new XElement("order",
                            new XAttribute("Item", "Widget"),
                            new XAttribute("Price", 100)
                      ),
                      new XElement("order",
                        new XAttribute("Item", "Tire"),
                        new XAttribute("Price", 200)
                      )
                    )
                )
            );
            Console.WriteLine(xdoc);
        }
    }








31.3.XAttribute
31.3.1.Linq To Xml Constructors
31.3.2.Use Linq to read xml file and query attribute value
31.3.3.Displays all the attributes from an Xml tag