Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath in Delphi7?

What is the best way of searching XML documents using XPath in Delphi7?

like image 460
Ricardo Acras Avatar asked Feb 05 '09 18:02

Ricardo Acras


2 Answers

It depends on the size of the xml document. But I have good experience with both MSXML and its Saxon counterpart.

If the xml is large (>50 MB) or the queries are heavy (use some // to make your system crawl) expect some delay time. But else it is perfectly doable.

In later versions, msxml is available as a unit. In version 7 you need to install a type library:

  • Go to Project\Import type library
  • Select Microsoft XML, (the highest version you can find)
  • Select Create unit to create MSXML_TLB

You can use MSXML_TLB to read xml documents, use xslt and perform xpath queries:

var
  doc  : IXMLDomDocument2;
  list : IXMLDomNodeList;
  node : IXMLDomNode;
  i    : Integer;

begin
  doc := CoDOMDocument.Create;
  doc.load(xmlfilename); 

  list := doc.selectNodes(xpath);
  for i := 0 to list.length-1 do begin
    node := list.item[i];
    if node<>nil then
      Memo1.Lines.Add(node.nodeName);
  end;
end;
like image 120
Toon Krijthe Avatar answered Nov 02 '22 10:11

Toon Krijthe


When I have to deal with XML files in Delphi I always use OmniXML, a component I've been using for years. I'm totally happy with it, mainly because it's light, easy to use and free.

And it works with XPath in a easy way also. It's worth a try, I hope it helps you also.

like image 1
SoftwareSculptor Avatar answered Nov 02 '22 10:11

SoftwareSculptor