Mega Code Archive

 
Categories / C# / XML LINQ
 

Create an XML tree with nested namespaces

using System; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){         XNamespace aw = "http://www.domain.com";         XNamespace fc = "www.yourDomain.com";         XDocument root = new XDocument(             new XDeclaration("1.0", "utf-8", "yes"),             new XElement(aw + "Root",                 new XElement(fc + "Child",                     new XElement(aw + "DifferentChild", "other content")                 )             )         );         Console.WriteLine(root);     } }