0

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


处理前文件中的内容,

<car id="wait for the signal &#10;&#10; then proceed &#9;">

处理文件后的内容,

<car id="wait for the signal &#xA;&#xA; then proceed &#x9;">

我使用的 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 文件中有十进制或十六进制实体,这两种情况都应该有效。但我专门寻找在处理文件后保留相同十进制实体的解决方案。

非常感谢任何帮助。

4

0 回答 0