也就是使用XPath的方式,具体语法规则查看http://www.w3school.com.cn/xpath/xpath_syntax.asp,说明得相当详细。这里列举例子是说明在Lazarus/FPC下具体应用于实现,以及注意事项。首先可以构建一个“ReadXPath”的函数方便调用。毕竟每次使用EvaluateXPathExpression后还有些任务要处理……。

  1. function ReadXPath(const aNode: TDOMNode; const aPath: string): TDOMNode;
  2. var
  3. rv: TXPathVariable;
  4. tl: TFPList;
  5. begin
  6. Result := nil;
  7. if Assigned(aNode) then
  8. begin
  9. rv := EvaluateXPathExpression(aPath, aNode);
  10. if Assigned(rv) then
  11. begin
  12. tl := rv.AsNodeSet;
  13. if Assigned(tl) then
  14. begin
  15. if tl.Count > 0 then
  16. begin
  17. Result := TDOMNode(tl[0]);
  18. end;
  19. end;
  20. end;
  21. end;
  22. end;

具体使用了,要记住返回的其实是“元素”,就算强制约定了“属性”——[@Attrib],所以要读取任何值,都要按“扫描到元素”的方式来处理。

  1. function ReadCFG: boolean;
  2. var
  3. .....
  4. vConfigXml: string = '';
  5. HistoryPath: string = '';
  6. TracePath: string = '';
  7. vXP: TDOMNode;
  8. .....
  9. begin
  10. Result := False;
  11. ReadXMLFile(xmlCfg, vConfigXml);
  12. vXP := ReadXPath(xmlCfg, '/Config/HistoryPath[@value]');
  13. if Assigned(vXP) then
  14. begin
  15. if vXP.HasAttributes then
  16. HistoryPath := vXP.Attributes.Item[0].NodeValue;
  17. end;
  18. vXP := ReadXPath(xmlCfg, '/Config/TracePath[@value]');
  19. if Assigned(vXP) then
  20. begin
  21. if vXP.HasAttributes then
  22. TracePath := vXP.Attributes.Item[0].NodeValue;
  23. end;
  24. if (HistoryPath <> '') and (TracePath <> '') then
  25. .....
  26. end;

Lazarus Reading XML- with TXMLDocument and TXPathVariable的更多相关文章

  1. WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误

    WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while ...

  2. [Bug]The maximum array length quota (16384) has been exceeded while reading XML data.

    写在前面 在项目中,有客户反应无法正常加载组织结构树,弄了一个测试的程序,在日志中查看到如下信息: Error in deserializing body of reply message for o ...

  3. WCF常见异常-The maximum string content length quota (8192) has been exceeded while reading XML data

    异常信息:The maximum string content length quota (8192) has been exceeded while reading XML data 问题:调用第三 ...

  4. The maximum string content length quota (8192) has been exceeded while reading XML data

    原文:The maximum string content length quota (8192) has been exceeded while reading XML data 问题场景:在我们W ...

  5. Lazarus Reading XML- with TXMLDocument and TDOMNode

    这里读取'HistoryPath' ,'TracePath' 元素下的‘value’属性使用的是 var xmlCfg: TXMLDocument; .... function ReadXMLCFG: ...

  6. 调用WebServiceWebService提示The maximum string content length quota (8192) has been exceeded while reading XML data的解决办法

    在web.config中,bindings节点下,对应的服务名称中,原本可能是自动折叠的“/>”,需要改成手动折叠的</binding>,然后在中间加上<readerQuota ...

  7. Using TXMLDocument, Working with XML Nodes

    Using TXMLDocument The starting point for working with an XML document is the Xml.XMLDoc.TXMLDocumen ...

  8. Lazarus中TreeView导出XML以及XML导入TreeView

    本来说是要给自己的某程序加一个xml导出功能,但是自己也没接触过xml,加之delphi和lazarus的xml部分还都不一样,折腾好久(整一天)才解决问题.. 如下是作为导出功能的组件部分: uni ...

  9. 查看 AndroidManifest.xml文件

    1.Manifest Explorer 装在Android手机中,用此apk看系统中已安装应用的AndroidManifest.xml文件: protected boolean configForPa ...

随机推荐

  1. 几道splay

    hdu 1890 题意:每次将第i位到第i小数字所在的位置之间的位置翻转,每次输出第i小数字所在的位置 分析: 简单的splay处理区间翻转问题 有三点需要注意: 1.区间是1~n+2 2.此题里的查 ...

  2. load函数

    load函数的作用 1.load函数的作用是,从server获取数据,而且把数据放到指定的元素(通常是div元素)中. 2.说的再具体一些就是,把获取到的数据插入到当前文档的某个div元素中. ser ...

  3. $.getJSON() 未能执行回调函数的缘由

    $.getJSON() 方法使用 AJAX 的 HTTP GET 请求获取 JSON 数据. 语法 1 $.getJSON(url,data,success(data,status,xhr)) url ...

  4. LeetCode 359. Logger Rate Limiter (记录速率限制器)$

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

  5. 关于ZEDboard

    核心芯片:核心ZYNQ XC7Z020CLG484 双核Cortex-A9 MPcore.主频达到667MHz,板载512MB内存 12V@3A的电源适配器 使用的SD卡中预装了Linaro系统,这是 ...

  6. LeetCode总结--二分查找篇

    二分查找算法尽管简单,但面试中也比較常见.经经常使用来在有序的数列查找某个特定的位置.在LeetCode用到此算法的主要题目有: Search Insert Position Search for a ...

  7. TLabel和TEdit的初次显示过程

    procedure TForm1.Button2Click(Sender: TObject); var l: TLabel;begin l:=TLabel.Create(self); l.Name:= ...

  8. X86架构下Linux启动过程分析

    1.X86架构下的从开机到Start_kernel启动的整体过程 这个过程简要概述为: 开机-->BIOS-->GRUB/LILO-->Linux Kernel 其执行的流程图和重要 ...

  9. luogu 1939 【模板】矩阵加速(数列)

    题目大意: a[1]=a[2]=a[3]=1 a[x]=a[x-3]+a[x-1] (x>3) 求a数列的第n项%1000000007 思路: 使用矩阵快速幂进行加速 在草稿纸上填了填数 然后就 ...

  10. P2120 [ZJOI2007]仓库建设 斜率优化dp

    好题,这题是我理解的第一道斜率优化dp,自然要写一发题解.首先我们要写出普通的表达式,然后先用前缀和优化.然后呢?我们观察发现,x[i]是递增,而我们发现的斜率也是需要是递增的,然后就维护一个单调递增 ...