XPath in Delphi7?

﹥>﹥吖頭↗ 提交于 2019-12-09 03:34:22

问题


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


回答1:


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;



回答2:


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.



来源:https://stackoverflow.com/questions/517145/xpath-in-delphi7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!