LINQ XML C# Book

When you construct a child XElement, you must give it a namespace explicitly if needed
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 XElement(ns + "customer", "Bloggs"), new XElement(ns + "purchase", "Bicycle")
);

Console.WriteLine(data);
}
}
The output:
BloggsBicycle