XmlDocument 不保存字符实体

本文关键字:实体 字符 保存 XmlDocument | 更新日期: 2023-09-27 18:34:38

我目前正在读取一个带有Xmldocument的xml文件并写入一些值。我正在阅读的部分看起来像这样:

<para styleclass="Normal" style="margin-top:12px; line-height:1.0; tabstops:none;"><table rowcount="22" colcount="4" style="width:100%; cell-padding:1px; cell-spacing:2px; page-break-inside:auto; border-width:0px; border-spacing:2px; cell-border-width:0px; border-style:none; background-color:none; head-row-background-color:none; alt-row-background-color:none;">
  <tr style="vertical-align:top">
    <td style="vertical-align:bottom; width:33%; background-color:#dddddd;">
      <para><text styleclass="Normal" style="font-size:9pt; font-weight:bold; vertical-align:baseline; color:#000000;" translate="true">&#32;</text></para>
    </td>
    <td style="vertical-align:bottom; width:22%; background-color:#dddddd;">
      <para style="text-align:center;"><text styleclass="Normal" style="font-size:9pt; font-weight:bold; vertical-align:baseline; color:#000000;" translate="true">Windows 32</text></para>
    </td>
    <td style="vertical-align:bottom; width:22%; background-color:#dddddd;">
      <para style="text-align:center;"><text styleclass="Normal" style="font-size:9pt; font-weight:bold; vertical-align:baseline; color:#000000;" translate="true">Windows 64</text></para>
    </td>
    <td style="vertical-align:bottom; width:22%; background-color:#dddddd;">
      <para style="text-align:center;"><text styleclass="Normal" style="font-size:9pt; font-weight:bold; vertical-align:baseline; color:#000000;" translate="true">Linux</text></para>
    </td>
  </tr>
  <tr style="vertical-align:top">
    <td style="vertical-align:bottom; background-color:#dddddd;">
      <para><text styleclass="Normal" style="font-size:9pt; font-weight:bold; vertical-align:baseline; color:#000000;" translate="true">SomeDll.dll</text></para>
    </td>
    <td style="width:22%;">
      <para style="text-align:center;"><text styleclass="Normal" style="font-size:9pt; vertical-align:baseline; color:#000000;" translate="true">1.0.4.78</text></para>
    </td>
    <td style="width:22%;">
      <para style="text-align:center;"><text styleclass="Normal" style="font-size:9pt; vertical-align:baseline; color:#000000;" translate="true">1.0.4.77</text></para>
    </td>
    <td style="width:22%;">
      <para style="text-align:center;"><text styleclass="Normal" style="font-size:9pt; vertical-align:baseline; color:#000000;" translate="true">to be defined</text></para>
    </td>
  </tr>

如您所见,在第二段中有一个字符实体(&# 3 2 ;)。我不编辑它,只是回顾它。完成编辑后,我使用 .save 方法保存文件。

问题是,字符实体被保存为它所代表的内容,在本例中为空格" "。如果我现在在我的程序中再次打开 xml 文件,我会得到一个异常,因为该值为 null。有没有办法将角色实体保存到其实体形式?

XmlDocument 不保存字符实体

鉴于难以

识别哪些实体被转换 - 例如,样本中有许多空格 - 将它们转换回来将非常困难。

如果您修改加载程序以允许转换实体的实例,可能会更容易。