XPath in Delphi7?
Asked Answered
N

2

6

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

Nose answered 5/2, 2009 at 18:14 Comment(0)
R
6

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;
Republicanize answered 5/2, 2009 at 18:40 Comment(1)
Thanks for your answere... How do I "install" MSXML in Delphi?Nose
T
1

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.

The answered 17/9, 2009 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.