gpt4 book ai didi

delphi - libxml2 xmlParseFile无法加载格式正确的XML

转载 作者:行者123 更新时间:2023-12-03 19:34:28 26 4
gpt4 key购买 nike

我是libxml2的新手,我很困惑为什么xmlParseFile总是返回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;


样本1.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
</root>


据报道,XML Spy 2007和xmllint工具格式良好。

我使用来自 http://xmlsoft.org的预编译DLL,并尝试同时使用DelphiAPI-2.6.26和libxml2-pas-2-7-3-src的此代码,但不走运。

我想我缺少了什么?

调试器仅跳过该行,因为它指向这样的外部引用:

function xmlParseFile (const filename: PChar) : xmlDocPtr; cdecl; external LIBXML2_SO;

最佳答案

归功于雷米,我将用答案代替他来结束这个问题:

将Delphi包装器从PChar(在XE和XE2中为PWideChar)更改为PAnsiChar可以解决此问题。一旦函数的定义更改为

function xmlParseFile (const filename: PWideChar) : xmlDocPtr; cdecl; 
external LIBXML2_SO;


工作正常。

关于delphi - libxml2 xmlParseFile无法加载格式正确的XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8667355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com