fix: update sitemap generation to use XmlWriter for improved XML handling
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled

- Changed the encoding in the XML declaration from "UTF-8" to "utf-8" for consistency.
- Replaced StringWriter with XmlWriter to enhance XML document writing and ensure proper encoding settings.
- Updated the return statement to convert the MemoryStream to a UTF-8 string, improving the efficiency of the sitemap generation process.

These changes enhance the reliability and correctness of the sitemap generation, ensuring better compliance with XML standards.
This commit is contained in:
masoodafar-web
2026-07-03 05:30:23 +03:30
parent 2573729db5
commit 06100ca6dd
@@ -1,4 +1,5 @@
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Extensions.Options;
@@ -71,16 +72,23 @@ public class SitemapGenerator
}
var document = new XDocument(
new XDeclaration("1.0", "UTF-8", null),
new XDeclaration("1.0", "utf-8", null),
new XElement(ns + "urlset", urls));
var builder = new StringBuilder();
using (var writer = new StringWriter(builder))
var settings = new XmlWriterSettings
{
Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false),
Indent = true,
OmitXmlDeclaration = false
};
using var stream = new MemoryStream();
using (var writer = XmlWriter.Create(stream, settings))
{
document.Save(writer);
}
return builder.ToString();
return Encoding.UTF8.GetString(stream.ToArray());
}
private static XElement CreateUrlElement(