SR wrote:
Quote:
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.
|
If you have
<foo xmlns="http://example.com/2008/ex1">
<bar>
<baz/>
</bar>
</foo>
then the namespace declaration on the foo element is in scope for the
descendants bar and baz too meaning if you want to create that snippet
with LINQ to XML you need
XNamespace ex1 = "http://goog-ajaxslt.sourceforge.net/";
XElement foo = new XElement(ex1 + "foo",
new XElement(ex1 + "bar",
new XElement(ex1 + "baz")));
Therefore if I understand you correctly then you want
Quote:
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
XElement elRoot = new XElement(ns + "urlset",
new XElement ("url",
|
new XElement(ns + "url",
Quote:
new XElement ("loc", "someurl...")
|
new XElement(ns + "loc", ...)
Quote:
),
new XElement ("url",
|
new XElement(ns + "url",
Quote:
new XElement ("loc", "someurl...")
|
new XElement(ns + "loc", ...)
If that does not achieve what you are looking for the please post the
XML you want to create.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/