[xml] =?ISO-8859-1?Q?XPATH=20Numbers=20don=27t=20work?=
- From: Uwe Fechner <ufechner 4commerce de>
- To: libxml2 <xml gnome org>
- Subject: [xml] XPATH Numbers don't work
- Date: Wed, 28 Nov 2001 13:26:42 +0100
Hello,
I am using libxml2.dll version 2.4.10 for windows. (from Igor).
I use the delphi-header-translations from
http://sourceforge.net/projects/libxml2-pas.
(Together with delphi 6.0 fixpack 1).
I have a problem using xpath.
The results are ok if they have the type nodeset.
Results of type number are always zero, strings are always empty.
Here my code:
Procedure test3(filename, expr: string);
// An Example Programm for the use of XPATH-expressions
// (without the xmldom.pas interface)
var doc: xmlDocPtr;
node: xmlNodePtr;
ctxt: xmlXPathContextPtr;
res: xmlXPathObjectPtr;
temp: string;
type_: integer;
number: double;
begin
// read the input file
filename:='..\data\'+filename;
StartTimer;
doc:=xmlParseFile(pchar(filename));
if doc<>nil then begin
outLog('Parsed file ok!');
outLog('Elapsed time: '+format('%8.1f',[EndTime*1000])+' ms');
end
else exit;
node:=xmlDocGetRootElement(doc);
if node=nil then exit;
// xpath
ctxt:=xmlXPathNewContext(doc);
ctxt.node:=node;
res:=xmlXPathEvalExpression(pchar(expr),ctxt);
//res:=xmlXPathEval(pchar(expr),ctxt);
if res=nil then exit;
type_:=res.type_;
case type_ of
XPATH_UNDEFINED:
begin
temp:='Undefined';
end;
XPATH_NODESET:
begin
temp:='Nodeset of '+inttostr(res.nodesetval.nodeNr)+' nodes';
end;
XPATH_BOOLEAN:
begin
if res.boolval=0
then temp:='Boolean: false'
else temp:='Boolean: true';
end;
XPATH_NUMBER:
begin
number:=res.floatval;
temp:='Number: '+floattostr(number);
end;
XPATH_STRING:
begin
temp:='String: '+res.stringval;
end;
else
begin
temp:='???';
end;
end;
outLog(temp);
xmlXPathFreeObject(res);
xmlXPathFreeContext(ctxt);
end;
If I test:
filename:='calServer.xml';
expr:='round(3)';
test3(filename,expr);
the output is:
Parsed file ok!
Elapsed time: 30,5 ms
Number: 0
If I test:
filename:='calServer.xml';
expr:='concat("uwe","fechner")';
test3(filename,expr);
the output is:
Parsed file ok!
Elapsed time: 16,5 ms
String:
Any idea?
Best regards:
Uwe Fechner
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]