我使用 XmlDocument 类来加载 XML 和 XmlWriter 类来生成文件。我想保留 xml 中存在的十进制字符实体(粗体字符),如下所示,
<car id="wait for the signal then proceed">
尝试了 XmlTextReader 之类的选项,但没有运气。处理文件中的上述行后,如下所示,
<car id="wait for the signal
then proceed">
或者
<car id="wait for the signal 

 then proceed">
我使用的 XmlWriter 代码块,
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings
{
Indent = true,
Encoding = encoding,
NewLineHandling = NewLineHandling.None
};
XmlDataDocument xmlDataDocument = new XmlDataDocument
{
PreserveWhitespace = true
};
xmlDataDocument.LoadXml(xmlString);
using (XmlWriter writer = XmlWriter.Create(filepath, xmlWriterSettings))
{
if (writer != null)
{
xmlDataDocument.Save(writer);
}
}
非常感谢任何帮助。