//Dependencies: //using System; using System.Xml.Linq;
//Let the compiler infer an XNamespace: XNamespace customNamespace = "urn:foo";
//Infer a custom namespace with prefix (with + operator overloading): XName customAttributeName = XNamespace.Xmlns + "rx";
//Generate an XAttribute from the above: XAttribute customAttribute = new XAttribute( customAttributeName, customNamespace.NamespaceName );
//Generate a custom element in our namespace (with + operator overloading): XElement custom = new XElement( customNamespace + "custom", "Hello world" );
//Generate an XML document with the namespace declared at document-level: XElement document = new XElement( "root", new Object[] { customAttribute, custom } );
Console.WriteLine( document.ToString() );
/* For more information see
“How to: Create a Document with Namespaces (LINQ to XML) (C#)”
http://msdn2.microsoft.com/en-us/library/bb387075(printer).aspx
and
“Atomized XName and XNamespace Objects”
http://blogs.msdn.com/ericwhite/pages/
atomized-xname-and-xnamespace-objects.aspx
Note: “To enable atomization of XName objects,
the constructor is not public, so you are not able
to directly instantiate an XName object.”
*/