我目前正在编写一个函数来为我的网络应用程序生成动态站点地图。
我正在使用带有反引号的模板字符串来构建它们,例如:
let sitemapXML = `
<urlset>
<url>
<loc>https://www.myproject.net/blog</loc>
<lastmod>${mostRecent.toISOString().slice(0,19) + '+00:00'}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
`;
虽然这在代码上看起来很棒,但它与 XML 语法有冲突,因为第一行有一个空行,而且它还使我的 XML 响应“丑陋”,带有一堆额外的空格。所以我正在考虑这样做:
// REMOVE ALL SPACES AND LINE BREAKS TO GET A SINGLE LINE STRING
sitemapXML = sitemapXML.replace(/" "/gm, "").replace(/\n/gm, "");
并使用 anxml-formatter
使其“漂亮”。
问题
此xml 格式化程序允许您选择换行符。我应该选择什么?\n
还是\r\n
?两者有区别还是没关系?