我在 XML 文件的属性中关注十进制实体	
以及
TAB 和 NEWLINE 字符。处理文件并保存后,上面的十进制实体分别替换为其十六进制等效项,即	
和

。
处理前文件中的内容,
<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.Replace
};
XmlDataDocument xmlDataDocument = new XmlDataDocument
{
PreserveWhitespace = true
};
xmlDataDocument.LoadXml(xmlString);
using (XmlWriter writer = XmlWriter.Create(filepath, xmlWriterSettings))
{
if (writer != null)
{
xmlDataDocument.Save(writer);
}
}
注意:我知道在 XML 文件中有十进制或十六进制实体,这两种情况都应该有效。但我专门寻找在处理文件后保留相同十进制实体的解决方案。
非常感谢任何帮助。