Using XNamespace to create nicely formatted XML

Using XNamespace to create nicely formatted XML

I want to create a Xml file that looks something like this:

<Root xmlns:ns1="name1" xmlns:ns2="name2">
    <ns1:element1 />
    <ns1:element2 />
    <ns2:element3 />

How can I accomplish this using XAttribute, XElement, XNamespace, and XDocument where the namespaces are dynamically added.

Trying out the examples from the “The Little Schemer” book in Windows


Syntax changes from the examples in 'The Little Schemer' to the real Scheme
I assume by "namespaces are dynamically added" you mean the namespace prefix.

Why does this script-fu not work?
This generates the document, how close is it to what you meant?.
Problem Installing Lispy Package Manager
        XNamespace ns1 = "name1", ns2 = "name2";          XElement elem = new XElement("Root",                  new XAttribute(XNamespace.Xmlns + "ns1", ns1),                  new XAttribute(XNamespace.Xmlns + "ns2", ns2),                 new XElement(ns1 + "element1"),                 new XElement(ns1 + "element2"),                 new XElement(ns2 + "element3"));          elem.Save("example.xml"); 

What's so great about Lisp? [closed]

81 out of 100 based on 81 user ratings 681 reviews