What is the best way of searching XML documents using XPath in Delphi7?
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:
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With