【发布时间】:2014-08-13 12:31:40
【问题描述】:
我生成了一个sitemap.xml
XDocument xDoc = new XDocument(
new XDeclaration("1.0", "UTF-8", ""),
new XElement("urlset",
new XAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"),
new Element (....and so on...)
我收到一个错误
前缀 '' 不能在同一起始元素标记中从 '' 重新定义为 'http://www.sitemaps.org/schemas/sitemap/0.9'。
Google 要求 xmlns 属性不带任何前缀。
【问题讨论】:
-
xmlns实际上不是一个属性。这是一个命名空间声明。它们看起来很相似,但 XML 认为它们是不同类型的东西,因此您不应该期望使用精心设计的 XML 库中的属性操作代码来操作它们。
标签: c# xml xml-namespaces xml-sitemap