XML sitemap remove xmlns from url tag

旧城冷巷雨未停 提交于 2020-05-29 06:48:25

问题


I am using the below lines to generate sitemap but google says there is an error. I know the error but i am unable to figure out how to remove the tag.

THe code

@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);
}

Output is

<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>

i want to remove the xmlns="" from the url tag.

<url xmlns="">

should be

<url>

来源:https://stackoverflow.com/questions/37879538/xml-sitemap-remove-xmlns-from-url-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!