Lazarus Reading XML- with TXMLDocument and TXPathVariable
也就是使用XPath的方式,具体语法规则查看http://www.w3school.com.cn/xpath/xpath_syntax.asp,说明得相当详细。这里列举例子是说明在Lazarus/FPC下具体应用于实现,以及注意事项。首先可以构建一个“ReadXPath”的函数方便调用。毕竟每次使用EvaluateXPathExpression后还有些任务要处理……。
- function ReadXPath(const aNode: TDOMNode; const aPath: string): TDOMNode;
- var
- rv: TXPathVariable;
- tl: TFPList;
- begin
- Result := nil;
- if Assigned(aNode) then
- begin
- rv := EvaluateXPathExpression(aPath, aNode);
- if Assigned(rv) then
- begin
- tl := rv.AsNodeSet;
- if Assigned(tl) then
- begin
- if tl.Count > 0 then
- begin
- Result := TDOMNode(tl[0]);
- end;
- end;
- end;
- end;
- end;
具体使用了,要记住返回的其实是“元素”,就算强制约定了“属性”——[@Attrib],所以要读取任何值,都要按“扫描到元素”的方式来处理。
- function ReadCFG: boolean;
- var
- .....
- vConfigXml: string = '';
- HistoryPath: string = '';
- TracePath: string = '';
- vXP: TDOMNode;
- .....
- begin
- Result := False;
- ReadXMLFile(xmlCfg, vConfigXml);
- vXP := ReadXPath(xmlCfg, '/Config/HistoryPath[@value]');
- if Assigned(vXP) then
- begin
- if vXP.HasAttributes then
- HistoryPath := vXP.Attributes.Item[0].NodeValue;
- end;
- vXP := ReadXPath(xmlCfg, '/Config/TracePath[@value]');
- if Assigned(vXP) then
- begin
- if vXP.HasAttributes then
- TracePath := vXP.Attributes.Item[0].NodeValue;
- end;
- if (HistoryPath <> '') and (TracePath <> '') then
- .....
- end;
Lazarus Reading XML- with TXMLDocument and TXPathVariable的更多相关文章
- 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 ...
- [Bug]The maximum array length quota (16384) has been exceeded while reading XML data.
写在前面 在项目中,有客户反应无法正常加载组织结构树,弄了一个测试的程序,在日志中查看到如下信息: Error in deserializing body of reply message for o ...
- 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 问题:调用第三 ...
- 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 ...
- Lazarus Reading XML- with TXMLDocument and TDOMNode
这里读取'HistoryPath' ,'TracePath' 元素下的‘value’属性使用的是 var xmlCfg: TXMLDocument; .... function ReadXMLCFG: ...
- 调用WebServiceWebService提示The maximum string content length quota (8192) has been exceeded while reading XML data的解决办法
在web.config中,bindings节点下,对应的服务名称中,原本可能是自动折叠的“/>”,需要改成手动折叠的</binding>,然后在中间加上<readerQuota ...
- Using TXMLDocument, Working with XML Nodes
Using TXMLDocument The starting point for working with an XML document is the Xml.XMLDoc.TXMLDocumen ...
- Lazarus中TreeView导出XML以及XML导入TreeView
本来说是要给自己的某程序加一个xml导出功能,但是自己也没接触过xml,加之delphi和lazarus的xml部分还都不一样,折腾好久(整一天)才解决问题.. 如下是作为导出功能的组件部分: uni ...
- 查看 AndroidManifest.xml文件
1.Manifest Explorer 装在Android手机中,用此apk看系统中已安装应用的AndroidManifest.xml文件: protected boolean configForPa ...
随机推荐
- 24、Java并发性和多线程-信号量
以下内容转自http://ifeve.com/semaphore/: Semaphore(信号量) 是一个线程同步结构,用于在线程间传递信号,以避免出现信号丢失(译者注:下文会具体介绍),或者像锁一样 ...
- SQL Server 性能优化实战系列(文章索引) : 桦仔
http://www.cnblogs.com/gaizai/archive/2012/01/20/2327814.html
- LVS中文站点
http://blog.csdn.net/turkeyzhou/article/details/16980161 http://zh.linuxvirtualserver.org/
- eclipse的Java项目修改后要不要重启tomcat问题
tomcat服务器重新部署工程或者修改了项目的代码就必须重启tomcat吗? 答: omcat服务器重新部署工程或者修改了项目的代码就必须重启tomcat吗?有没有不重启的方法,或者其他高效点的,让服 ...
- 【CV论文阅读】Going deeper with convolutions(GoogLeNet)
目的: 提升深度神经网络的性能. 一般方法带来的问题: 增加网络的深度与宽度. 带来两个问题: (1)参数增加,数据不足的情况容易导致过拟合 (2)计算资源要求高,而且在训练过程中会使得很多参数趋向于 ...
- MyEclipse 9.0 正式版公布新闻 下载
MyEclipse 9.0 正式版公布 新闻 ============================================================================ ...
- zoj3605 Find the Marble --- 概率dp
n个杯子.球最開始在s位置.有m次换球操作,看到了k次,看的人依据自己看到的k次猜球终于在哪个位置,输出可能性最大的位置. dp[m][k][s]表示前m次操作中看到了k次球终于在s的频率. #inc ...
- LeetCode 206. Reverse Linked List (倒转链表)
Reverse a singly linked list. 题目标签:Linked List 题目给了我们一个链表,要求我们倒转链表. 利用递归,新设一个newHead = null,每一轮 把下一个 ...
- Hadoop Yarn(一)—— 单机伪分布式环境安装
HamaWhite(QQ:530422429)原创作品,转载请注明出处:http://write.blog.csdn.net/postedit/40556267. 本文是依据Hadoop官网安装教程写 ...
- cts帧
RTS/CTS机制的工作原理是.发送网站在向接收网站发送数据包之前.即在DIFS之后不是马上发送数据,而是代之以发送一个请求发送RTS(Ready To Send)帧,以申请对介质的占用,当接收 ...