加载有效的 Windows-1252 文档时出错“系统错误:-2146697210”
不知何故,有时下面的代码在加载有效的 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 上也能正常运行)。
——杰罗恩
Somehow, sometimes the code below generates an error when loading valid Windows-1252 XML.
It fails on Windows XP Professional x86 SP3 using MSXML6.
It succeeds on Windows 7 Ultimate x64 SP1 using MSXML6.
Note: the code below is written in Delphi, but equivalent code also fails in other environments.
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;
This error occurs during the XmlDocument.load method:
reason: System error: -2146697210.
errorCode: -2146697210
url: C:\temp\1-Normal.xml
I trimmed the XML down to the XML found below.
This is the hex dump of the XML file:
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="."/>..
This is the XML:
<?xml version = "1.0" encoding="Windows-1252"?><ROW City="à"/>
Why does the error occur?
(The XML loads perfectly fine in .NET and other environments not using MSXML6, it also works fine on Windows 7 Ultimate x64 SP1).
--jeroen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该行为取决于您安装的
MSXML6.DLL
版本。为了更好地重现这一点,我创建了另一个文件
abnormal.xml
,位于除了问题中的normal.xml
之外。文件转储
abnormal.xml
:文件
abnormal.xml
:文件转储
normal.xml
:文件
normal.xml
:我期望的行为是:
abnormal.xml
失败,因为它没有指定编码,但包含具有高位集的字符normal.xml
成功,如下它包含支持高位字符的单字节编码,因此允许使用高位集的字符这些是观察到的场景:
MSXML6 失败:
MSXML6 成功:
这是失败版本的概述。
括号之间的 DLL 名称来自其版本信息。
观察:
因此:在执行 MSXML6 工作时,首先检查您是否确实拥有适合您的目标 Windows 版本的最新 MSXML6.DLL。
——杰罗恩
The behaviour depends on which version of the
MSXML6.DLL
you have installed.To reproduce this better, I created another file
abnormal.xml
, in addition to thenormal.xml
from the question.File dump
abnormal.xml
:File
abnormal.xml
:File dump
normal.xml
:File
normal.xml
:The behaviour I expect is that:
abnormal.xml
fails, because it does not specify an encoding, but contains a character with the high-bit setnormal.xml
succeeds, as it conains a single-byte encoding supporting high-bit characters, so characters with high-bit set are allowedThese are the observed scenarios:
MSXML6 FAILURE:
MSXML6 SUCCESS:
This is an overview of what versions fail.
The names of the DLL's between parentheses are from their version information.
Observations:
So: when doing MSXML6 work, first put in a check that you indeed have the latest MSXML6.DLL for your target Windows version.
--jeroen