我想创建一个使用Linq到Xml的站点地图,但是我得到一个空的名称空间属性,我想摆脱它。例如使用Linq 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>
我宁愿没有的xmlns = “” 的URL元素。我可以在最终的xdoc.ToString()上使用Replace来剥离它,但是有没有更正确的方法?
非常好。谢谢。 – peterorum 2008-09-14 05:22:32