[xml] Nodeset problem



Hello,

I am not able to work with nodeSets in the moment.

The appended programm delivers this result:

Parsed file ok! Elapsed time:     23,7 ms
Nodeset of 1 nodes
Nodemax is 10 nodes
nodeset[0] = nil

Both of the following lines deliver nil, even though
they shall not:
(They are equivalent.)

node1:=xmlXPathNodeSetItem(NodeSet,i);
//node1:= NodSet^.nodeTab^[i];

Any idea?

I work with the libxml2 version 2.4.12 from
http://www.fh-frankfurt.de/~igor/projects/libxml/.

Best regards:

Uwe Fechner


procedure testNodeSet(filename:string);
// An Example Programm for the use of NodeSets
// (without the xmldom.pas interface)
var doc: xmlDocPtr;
    node,node1: xmlNodePtr;
    nodeSet:  xmlNodeSetPtr;
    temp: string;
    type_,i,nodecount,nodemax: integer;
    temp1: string;
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);
  nodeSet:=xmlXPathNodeSetCreate(node);
  if node=nil then exit;
      begin
        nodecount:=NodeSet.nodeNr;
        temp:='Nodeset of '+inttostr(nodecount)+' nodes';
        OutLog(temp);
        nodemax:=NodeSet.nodeMax;
        temp:='Nodemax is '+inttostr(nodemax)+' nodes';
        OutLog(temp);
        for i:=0 to nodecount-1 do begin
          node1:=xmlXPathNodeSetItem(NodeSet,i);
          //node1:= NodSet^.nodeTab^[i];
          if node1<>nil
            then begin
              //temp1:=node1.name;
              outLog('nodeset['+inttostr(i)+'] <> nil; node.name: '+temp1);
            end
            else outLog('nodeset['+inttostr(i)+'] = nil');
        end;
      end;
  xmlXPathFreeNodeSet(NodeSet);
  xmlFreeDoc(doc);
end;




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]