public static void Main(string[] args)
XNamespace ns = "http://tempuri.org/NBAppSchema.xsd";
var doc = new XDocument(new XElement("root", new XAttribute("attr1", "val1"), new XElement("SubNode")));
Console.WriteLine(doc.ToString());
doc.Root.Add(new XAttribute(XNamespace.Xmlns + "ns", ns));
doc.Root.Add(new XElement(ns+"NSSubNode", new XAttribute("attr2", "val2")));
Console.WriteLine(doc.ToString());
var doc2 = new XDocument(new XElement(ns + "root", new XAttribute("attr1", "val1"), new XElement(ns + "SubNode")));
Console.WriteLine(doc2.ToString());