Being new to libxml2 I am confused why xmlParseFile always returns nil
uses
libxml2;
procedure TForm1.FormCreate(Sender: TObject);
var
doc: xmlDocPtr;
begin
doc := xmlParseFile('1.xml'); // doc is nil
doc := xmlParseFile('c:\1.xml'); // doc is again nil
end;
Sample 1.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
</root>
The xml is reported to be well-formed by both XML Spy 2007 and xmllint tools.
I use the precompiled DLLs from http://xmlsoft.org and tries this code with both DelphiAPI-2.6.26 and libxml2-pas-2-7-3-src without luck.
I guess I am missing something?
The debugger just jumps over the line since it points to an external reference like this:
function xmlParseFile (const filename: PChar) : xmlDocPtr; cdecl; external LIBXML2_SO;
With all credit going to Remy I will put the answer instead of him to have this closed:
Changing the Delphi wrapper from PChar (which is PWideChar in XE and XE2) to PAnsiChar resolved the problem. Once the definition of the function was changed to
it worked fine.