XML站点地图从url标记中删除xmlns

时间:2016-06-17 10:41:41

标签: asp.net xml razor webmatrix

我使用以下行生成站点地图,但Google表示存在错误。我知道错误,但我无法弄清楚如何删除标签。

代码

  cookie:
   { path: '/',
     _expires: null,
     originalMaxAge: null,
     httpOnly: true },
  passport: { user: '5760703f8fd744e020920980' } }

输出

@using System.Xml.Linq;
@{
Layout = null;
var urls = new List<string>{
  "1", "2", "3"
};
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
var baseurl = "http://www.myurl.in/{0}";
var sitemap = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
        new XElement(ns + "urlset", 
            from url in urls select
            new XElement("url",
                new XElement("loc", string.Format(baseurl, url)),
                new XElement("lastmod", string.Format("{0}{1}", DateTime.Now.ToString("s"), DateTime.Now.ToString("%K"))),
                new XElement("changefreq", "monthly"),
                new XElement("priority", "0.5")
            )
        )  
);
Response.ContentType = "text/xml";
sitemap.Save(Response.Output);
}

我想删除xmlns =&#34;&#34;来自网址标记。

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url xmlns="">
    <loc>http://www.myurl.in/1</loc>
    <lastmod>2016-06-17T15:19:27+05:30</lastmod>
    <changefreq>daily</changefreq>
</url>
<url xmlns="">
    <loc>http://www.myurl.in/2</loc>
    <lastmod>2016-06-17T15:19:27+05:30</lastmod>
    <changefreq>daily</changefreq>
</url>
<url xmlns="">
    <loc>http://www.myurl.in/3</loc>
    <lastmod>2016-06-17T15:19:27+05:30</lastmod>
    <changefreq>daily</changefreq>
</url>

应该是

<url xmlns="">

0 个答案:

没有答案