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 ...
随机推荐
- Solidworks如何另存为和打开OBJ文件
1 点击工具-插件,勾选ScanTo3D(最好后面的启动也勾选上,否则下次启动将不会默认自动启动这个插件,还需要再做一次才能打开或者另存为OBJ) 2 注意打开零件图的方式,你不能直接打开Soli ...
- 从头认识java-15.1 填充容器(1)-利用Collection构造器的方式
这一章节我们来介绍一下填充容器. 就像数组一样,Arrays.fill是填充方法,在容器里面也有. 1.Collections.nCopies 这种方法是生成某种类型多少个对象,然后我们能够把他放到容 ...
- MySQL 入门(九)—— 查询数据
查询数据就是从数据库中获取所须要的数据. 1.基本查询语句 即Select语句 当中.属性列表表示要查询的字段名.表名和视图列表表示从此处指定的表或者视图中查询数据.能够有多个:条件表达式1制定了查询 ...
- Ubuntu14 中安装 VMware10 Tools工具<2>
网上说已经针对上一篇提到的无法显示共享文件夹的问题做了补丁.补丁地址是https://github.com/rasa/vmware-tools-patches,我没有成功,还是出现"hgfs ...
- 转 java synchronized详解
转自 http://www.cnblogs.com/GnagWang/archive/2011/02/27/1966606.html Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能 ...
- mms
Quartz2D 二维绘图引擎(绘制图形|绘制文字|读取生成 PDF|裁剪图片|自定义 UI 控件) 继承 UIView 重写 drawRect.(viewDidLoad->viewWillAp ...
- java.io.IOException: The same input jar is specified twice
简介: eclipse android proguard 打包时出现 java.io.IOException: The same input jar is specified twice 错误, 这里 ...
- 2017iOS开发最新的打包测试步骤(亲测)
最近也是忙着修改项目,今天把最近遇到的问题和知识给大家分享一下. 有时候我们需要将我们的项目发给测试组进行bug测试,这时候我们就需要把自己的项目打包,生成一个二维码或者链接的形式,给测试组,接下来就 ...
- 【HNOI 2003】 激光炸弹
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1218 [算法] 二维前缀和 [代码] #include<bits/stdc++ ...
- Hadoop - WordCount代码示例
文章来源:http://www.itnose.net/detail/6197823.html import java.io.IOException; import java.util.Iterator ...