3

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>
Gautam Sharma
  • 65
  • 1
  • 7
  • Does this answer your question? [How can I remove empty xmlns attribute from node created by XElement](https://stackoverflow.com/questions/12038636/how-can-i-remove-empty-xmlns-attribute-from-node-created-by-xelement) – peinearydevelopment May 19 '20 at 18:14

0 Answers0