也就是使用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. 24、Java并发性和多线程-信号量

    以下内容转自http://ifeve.com/semaphore/: Semaphore(信号量) 是一个线程同步结构,用于在线程间传递信号,以避免出现信号丢失(译者注:下文会具体介绍),或者像锁一样 ...

  2. SQL Server 性能优化实战系列(文章索引) : 桦仔

    http://www.cnblogs.com/gaizai/archive/2012/01/20/2327814.html

  3. LVS中文站点

    http://blog.csdn.net/turkeyzhou/article/details/16980161 http://zh.linuxvirtualserver.org/

  4. eclipse的Java项目修改后要不要重启tomcat问题

    tomcat服务器重新部署工程或者修改了项目的代码就必须重启tomcat吗? 答: omcat服务器重新部署工程或者修改了项目的代码就必须重启tomcat吗?有没有不重启的方法,或者其他高效点的,让服 ...

  5. 【CV论文阅读】Going deeper with convolutions(GoogLeNet)

    目的: 提升深度神经网络的性能. 一般方法带来的问题: 增加网络的深度与宽度. 带来两个问题: (1)参数增加,数据不足的情况容易导致过拟合 (2)计算资源要求高,而且在训练过程中会使得很多参数趋向于 ...

  6. MyEclipse 9.0 正式版公布新闻 下载

    MyEclipse 9.0 正式版公布 新闻 ============================================================================ ...

  7. zoj3605 Find the Marble --- 概率dp

    n个杯子.球最開始在s位置.有m次换球操作,看到了k次,看的人依据自己看到的k次猜球终于在哪个位置,输出可能性最大的位置. dp[m][k][s]表示前m次操作中看到了k次球终于在s的频率. #inc ...

  8. LeetCode 206. Reverse Linked List (倒转链表)

    Reverse a singly linked list. 题目标签:Linked List 题目给了我们一个链表,要求我们倒转链表. 利用递归,新设一个newHead = null,每一轮 把下一个 ...

  9. Hadoop Yarn(一)—— 单机伪分布式环境安装

    HamaWhite(QQ:530422429)原创作品,转载请注明出处:http://write.blog.csdn.net/postedit/40556267. 本文是依据Hadoop官网安装教程写 ...

  10. cts帧

     RTS/CTS机制的工作原理是.发送网站在向接收网站发送数据包之前.即在DIFS之后不是马上发送数据,而是代之以发送一个请求发送RTS(Ready To Send)帧,以申请对介质的占用,当接收 ...