XPath在Delphi7中? [英] XPath in Delphi7?

查看:414
本文介绍了XPath在Delphi7中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi7中使用XPath搜索XML文档的最佳方式是什么?

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

推荐答案

这取决于xml的大小文件。但是我对MSXML和它的Saxon对手有很好的经验。

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

如果xml很大(> 50 MB)或查询很重(使用一些//来做您的系统爬网)预计会有一些延迟时间。但是它是完全可行的。

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.

在更高版本中,msxml可作为一个单元使用。在版本7中,您需要安装一个类型库:

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


  • 转到Project\Import类型库

  • 选择Microsoft XML(最高版本可以找到)

  • 选择创建单位创建MSXML_TLB

您可以使用MSXML_TLB读取xml文档,使用xslt和执行xpath查询:

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;

这篇关于XPath在Delphi7中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆