Linq to Xml を使用してサイトマップを作成しようとしていますが、削除したい空の名前空間属性を取得しています。例えば
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
new XElement(ns + "urlset",
new XElement("url",
new XElement("loc", "http://www.example.com/page"),
new XElement("lastmod", "2008-09-14"))));
結果は...
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url xmlns="">
<loc>http://www.example.com/page</loc>
<lastmod>2008-09-14</lastmod>
</url>
</urlset>
url 要素に xmlns="" を付けたくないのです。最終的な xdoc.ToString() で Replace を使用して削除できますが、もっと正しい方法はありますか?