CSharp - Set a Namespace Prefix To via the XAttribute object

Description

Set a Namespace Prefix To via the XAttribute object

Demo

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

class Program/*  w w  w.  j  a  va  2  s  .  c om*/
{
    static void Main(string[] args){
          XNamespace nameSpace = "http://www.book2s.com";

      XElement xBookParticipants =
        new XElement(nameSpace + "BookParticipants",
          new XAttribute(XNamespace.Xmlns + "linqdev", nameSpace),
          new XElement(nameSpace + "BookParticipant"));

      Console.WriteLine(xBookParticipants.ToString());
    }
}

Result

Related Topic