XNamespace

Specifying a namespace is the same whether for an element or an attribute:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main()
    {
        XNamespace ns = "http://domain.com/xmlspace";
        var data = new XElement(ns + "data",
        new XAttribute(ns + "id", 123)
        );
        
        Console.WriteLine(data);
    }
}

The output:

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.