fix: update sitemap generation to use XmlWriter for improved XML handling
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
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:
@@ -1,4 +1,5 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@@ -71,16 +72,23 @@ public class SitemapGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
var document = new XDocument(
|
var document = new XDocument(
|
||||||
new XDeclaration("1.0", "UTF-8", null),
|
new XDeclaration("1.0", "utf-8", null),
|
||||||
new XElement(ns + "urlset", urls));
|
new XElement(ns + "urlset", urls));
|
||||||
|
|
||||||
var builder = new StringBuilder();
|
var settings = new XmlWriterSettings
|
||||||
using (var writer = new StringWriter(builder))
|
{
|
||||||
|
Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false),
|
||||||
|
Indent = true,
|
||||||
|
OmitXmlDeclaration = false
|
||||||
|
};
|
||||||
|
|
||||||
|
using var stream = new MemoryStream();
|
||||||
|
using (var writer = XmlWriter.Create(stream, settings))
|
||||||
{
|
{
|
||||||
document.Save(writer);
|
document.Save(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.ToString();
|
return Encoding.UTF8.GetString(stream.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static XElement CreateUrlElement(
|
private static XElement CreateUrlElement(
|
||||||
|
|||||||
Reference in New Issue
Block a user