Description

Add Namespace to Element

Demo

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

class Program/*from  ww  w . j  av a2 s . com*/
{
    static void Main(string[] args){
          XNamespace nameSpace = "http://www.book2s.com";

      XElement xBookParticipants =
        new XElement(nameSpace + "BookParticipants",
          new XElement(nameSpace + "BookParticipant",
            new XAttribute("type", "Author"),
            new XElement(nameSpace + "FirstName", "Joe"),
            new XElement(nameSpace + "LastName", "Ruby")),
          new XElement(nameSpace + "BookParticipant",
            new XAttribute("type", "Editor"),
            new XElement(nameSpace + "FirstName", "Ewan"),
            new XElement(nameSpace + "LastName", "Buckingham")));

      Console.WriteLine(xBookParticipants.ToString());

    }
}

Result

Related Topic