first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

LINQ to XML: Generating XML with a Custom Namespace; System.Xml.Linq

//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.”

*/

mod date: 2008-03-23T03:58:42.000Z