【问题标题】:Error when loading valid Windows-1252 document "System error: -2146697210"加载有效的 Windows-1252 文档“系统错误:-2146697210”时出错
【发布时间】:2012-07-14 03:38:53
【问题描述】:

不知何故,有时下面的代码在加载有效的 Windows-1252 XML 时会产生错误。

在使用 MSXML6 的 Windows XP Professional x86 SP3 上失败。
它在使用 MSXML6 的 Windows 7 Ultimate x64 SP1 上成功。

注意:下面的代码是用 Delphi 编写的,但是在其他环境下等效的代码也会失败。

procedure TXMLEOSErrorTestCase.Test;
var
  XmlDocument: IXMLDOMDocument3;
  XmlFileName: string;
begin
  XmlDocument := CoFreeThreadedDOMDocument60.Create();
  XmlFileName :=  TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), '1-Normal.xml');
  if not XmlDocument.load(XmlFileName) then
    Parse(XmlDocument.parseError);
end;

XmlDocument.load 方法期间出现此错误:

reason: System error: -2146697210.
errorCode: -2146697210
url: C:\temp\1-Normal.xml

我将 XML 精简为下面找到的 XML。

这是 XML 文件的十六进制转储:

000000: 3C 3F 78 6D 6C 20 76 65  72 73 69 6F 6E 20 3D 20 <?xml version =
000010: 22 31 2E 30 22 20 65 6E  63 6F 64 69 6E 67 3D 22 "1.0" encoding="
000020: 57 69 6E 64 6F 77 73 2D  31 32 35 32 22 3F 3E 3C Windows-1252"?><
000030: 52 4F 57 20 43 69 74 79  3D 22 E0 22 2F 3E 0D 0A ROW City="."/>..

这是 XML:

<?xml version = "1.0" encoding="Windows-1252"?><ROW City="à"/>

为什么会出现错误?

(XML 在 .NET 和其他不使用 MSXML6 的环境中加载非常好,它在 Windows 7 Ultimate x64 SP1 上也可以正常工作)。

--杰罗恩

【问题讨论】:

  • 这样的错误代码更常用十六进制写成:800C0006。这意味着“系统无法找到指定的对象”。 (这是我所知道的限制。)我想知道编码是否与问题有关?如果您指定不同的编码怎么办?如果您保留现有的编码,但只使用 ASCII 字符会怎样?
  • 就是这样:它是那个字符和编码的组合。它适用于 Windows 7。所以它也与 MSXML6 版本有关。我现在正在调查版本号。完成后会总结(可能明天)

标签: msxml msxml6


【解决方案1】:

行为取决于您安装的MSXML6.DLL 的版本。

为了更好地重现这一点,除了问题中的 normal.xml 之外,我还创建了另一个文件 abnormal.xml

文件转储abnormal.xml:

000000: 3C 3F 78 6D 6C 20 76 65  72 73 69 6F 6E 3D 22 31 <?xml version="1
000010: 2E 30 22 20 73 74 61 6E  64 61 6C 6F 6E 65 3D 22 .0" standalone="
000020: 79 65 73 22 3F 3E 3C 52  4F 57 20 43 69 74 79 3D yes"?><ROW City=
000030: 22 E0 22 2F 3E 0D 0A                             "."/>..

文件abnormal.xml

<?xml version="1.0" standalone="yes"?><ROW City="à"/>

文件转储normal.xml:

000000: 3C 3F 78 6D 6C 20 76 65  72 73 69 6F 6E 20 3D 20 <?xml version =
000010: 22 31 2E 30 22 20 65 6E  63 6F 64 69 6E 67 3D 22 "1.0" encoding="
000020: 57 69 6E 64 6F 77 73 2D  31 32 35 32 22 3F 3E 3C Windows-1252"?><
000030: 52 4F 57 20 43 69 74 79  3D 22 E0 22 2F 3E 0D 0A ROW City="."/>..

文件normal.xml

<?xml version = "1.0" encoding="Windows-1252"?><ROW City="à"/>

我期望的行为是:

  1. abnormal.xml 失败,因为它没有指定编码,但包含一个高位集的字符
  2. normal.xml 成功,因为它包含支持高位字符的单字节编码,因此允许设置高位字符的字符

这些是观察到的场景:

MSXML6 失败:

reason: System error: -2146697210.
errorCode: -2146697210
url: file:///C:/My%20Dropbox/XMLEOSErrorTest/Abnormal.xml

reason: System error: -2146697210.
errorCode: -2146697210
url: file:///C:/My%20Dropbox/XMLEOSErrorTest/Normal.xml

MSXML6 成功:

reason: An invalid character was found in text content.

errorCode: -1072896760
url: file:///C:/My%20Dropbox/XMLEOSErrorTest/Abnormal.xml
srcText: <?xml version="1.0" standalone="yes"?><ROW City="
line: 1
linepos: 50
filepos: 49

这是对哪些版本失败的概述。
括号中的 DLL 名称来自它们的版本信息。

failure; XP Professional SP3:
msxml6.dll       version 6.20.1099.0  (MSXML 6.0 SP2)
msxml6r.dll      version 6.0.3883.0   (XML Resources)

success; Windows 7 Ultimate x64 SP1:
msxml6.dll       version 6.30.7600.16385  (MSXML 6.0 SP3)
msxml6r.dll      version 6.30.7600.16385
msxml6r.dll.mui  version 6.30.7600.16385

success; XP Professional SP3:
msxml6.dll       version 6.20.1103.0  (MSXML 6.0 SP3)
msxml6r.dll      version 6.0.3883.0   (XML Resources)

观察:

所以:在进行 MSXML6 工作时,首先检查您是否确实拥有适用于您的目标 Windows 版本的最新 MSXML6.DLL。

--杰罗恩

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多