也就是使用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. oracle约束总结(not null/unique/primary key/foreign key/check)

    约束(constraint):对创建的表的列属性.字段进行的限制. 诸如:not null/unique/primary key/foreign key/check 作用范围:         ①列级 ...

  2. LeetCode 739. Daily Temperatures (每日温度)

    题目标签:HashMap 题目给了我们一组温度,让我们找出 对于每一天,要等多少天,气温会变暖.返回一组等待的天数. 可以从最后一天的温度遍历起,从末端遍历到开头,对于每一天的温度,把它在T里面的in ...

  3. LeetCode 246. Strobogrammatic Number (可颠倒数字) $

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  4. Mysql经常使用函数

    -----------------------------字符串函数--------------------------------------- ----拼接字符串.不论什么字符串与null拼接为n ...

  5. js 里面的 function 与 Function

    function 是 js 的标识符 Function 是 js 里面的一个 构造函数 1.new function 与 new Function 的区别 new 运算符在 js 里面是 创建一个自定 ...

  6. UVA - 10324 Zeros and Ones

    Description Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are ...

  7. android binder 基础实例及解析(一)【转】

    本文转载自:http://blog.csdn.net/newchenxf/article/details/49359283#insertcode 原文网址(转载请注明出处): http://blog. ...

  8. Configuration.SectionGroups

    对于一个空的配置文件,默认自带的sectiongroups 默认有10个section节点 1 ConfigurationSectionGroupName=system.runtime.seriali ...

  9. ubuntu安装vmware 64位

    1.从官网上获取http://www.vmware.com/products/workstation/workstation-evaluation.html 2.执行安装程序 chmod +x VMw ...

  10. yum -y --downloadonly --downloaddir=/ruiy upggrde;

    事务概要================================================================================================ ...