“A call to an OS function failed” when loading Windows-1252 XML file


The error was indeed in the handling; parseError also fails ans reveals the real error; see follow-up question for that error.

Old question:

Somehow, sometimes the code below generates an exception when loading XML using the msxml unit in Delphi XE. It fails on Windows XP Professional x86 SP3 using MSXML6 and Windows 7 Ultimate x64 SP1 using MSXML6.

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

This error occurs during the XmlDocument.load method:

EOSError at  $00423B2D
A call to an OS function failed

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).



As you can see in SysUtils.pas, that error message is the one that's given when GetLastError returns zero. The documentation for IXmlDomDocument.load does not advise you to call GetLastError to discover the reason for the failure. The last-error value for your thread is probably the default zero value.

Instead, inspect the document object's parseError value. It will give you an IXmlDomParseError object that tells you where and why the problem occurred.

Need Your Help

UIView Overgive Value

iphone uiview

when calling another UIView how can I send a value:

Loading an image using OpenCV in Android

java android image opencv

I apologize if this question has already been covered on this site, but I can't seem to find a straight forward answer. I'm making an android app that uses OpenCV to take a picture, process it to d...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.