Please, see the following image:
In English:
XML Parsing Error: XML or text declaration not at start of entity. Location: https:// ****.com/sitemap Line Number 4, Column 1:
I can't properly create a sitemap, because I'm always stuck on that error. I don't know why but it seems like XmlWriter
is adding exactly 3 blank lines before my xml
tag. I've tried playing with XmlWriterSettings and lots of different things at no avail.
This is part of my code:
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml;";
context.HttpContext.Response.ContentEncoding = Encoding.UTF8;
using (XmlWriter writer = new XmlTextWriter(context.HttpContext.Response.Output))
{
writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
...
writer.WriteEndElement();
writer.Flush();
writer.Close();
}
}
Does anyone have any idea on how to solve this? Thanks!