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 ...
随机推荐
- oracle约束总结(not null/unique/primary key/foreign key/check)
约束(constraint):对创建的表的列属性.字段进行的限制. 诸如:not null/unique/primary key/foreign key/check 作用范围: ①列级 ...
- LeetCode 739. Daily Temperatures (每日温度)
题目标签:HashMap 题目给了我们一组温度,让我们找出 对于每一天,要等多少天,气温会变暖.返回一组等待的天数. 可以从最后一天的温度遍历起,从末端遍历到开头,对于每一天的温度,把它在T里面的in ...
- LeetCode 246. Strobogrammatic Number (可颠倒数字) $
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...
- Mysql经常使用函数
-----------------------------字符串函数--------------------------------------- ----拼接字符串.不论什么字符串与null拼接为n ...
- js 里面的 function 与 Function
function 是 js 的标识符 Function 是 js 里面的一个 构造函数 1.new function 与 new Function 的区别 new 运算符在 js 里面是 创建一个自定 ...
- 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 ...
- android binder 基础实例及解析(一)【转】
本文转载自:http://blog.csdn.net/newchenxf/article/details/49359283#insertcode 原文网址(转载请注明出处): http://blog. ...
- Configuration.SectionGroups
对于一个空的配置文件,默认自带的sectiongroups 默认有10个section节点 1 ConfigurationSectionGroupName=system.runtime.seriali ...
- ubuntu安装vmware 64位
1.从官网上获取http://www.vmware.com/products/workstation/workstation-evaluation.html 2.执行安装程序 chmod +x VMw ...
- yum -y --downloadonly --downloaddir=/ruiy upggrde;
事务概要================================================================================================ ...