How can I remove an empty namespace with XElement ?
Using the below code I wish to apply the namespace only to the root node
<urlsetbut I obtain also an empty xmlns="" on the child nodes.
Thanks
Sandro
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
XElement elRoot = new XElement(ns + "urlset",
new XElement ("url",
new XElement ("loc", "someurl...")
),
new XElement ("url",
new XElement ("loc", "someurl...")
)
);
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
elRoot
);
doc.Save(Console.Out);
Console.ReadLine();
Result:
<?xml version="1.0" encoding="ibm850" standalone="yes"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url xmlns="">
<loc>someurl...</loc>
</url>
<url xmlns="">
<loc>someurl...</loc>
</url>
</urlset>