TXMLDocument use case (Delphi)
Description
This example illustrates the basic operations on an XML document.
Code
procedure CreateDocument;
const
CFilename = 'file.xml';
var
LDocument: IXMLDocument;
LNodeElement, NodeCData, NodeText: IXMLNode;
begin
LDocument := TXMLDocument.Create(nil);
LDocument.Active := True; { Define document content. }
LDocument.DocumentElement := LDocument.CreateNode('ThisIsTheDocumentElement', ntElement, '');
LDocument.DocumentElement.Attributes['attrName'] := 'attrValue';
LNodeElement := LDocument.DocumentElement.AddChild('ThisElementHasText', -1);
LNodeElement.Text := 'Inner text.';
NodeCData := LDocument.CreateNode('any characters here', ntCData, '');
LDocument.DocumentElement.ChildNodes.Add(NodeCData);
NodeText := LDocument.CreateNode('This is a text node.', ntText, '');
LDocument.DocumentElement.ChildNodes.Add(NodeText); LDocument.SaveToFile(CFilename);
end; procedure RetrieveDocument;
const
CFilename = 'file.xml';
CAttrName = 'attrName';
HTAB = #9;
var
LDocument: IXMLDocument;
LNodeElement, LNode: IXMLNode;
LAttrValue: string;
I: Integer;
begin
LDocument := TXMLDocument.Create(nil);
LDocument.LoadFromFile(CFilename); { Find a specific node }
LNodeElement := LDocument.ChildNodes.FindNode('ThisIsTheDocumentElement'); if (LNodeElement <> nil) then
begin
{ Get a specific attribute }
Writeln('Getting attribute...');
if (LNodeElement.HasAttribute(CAttrName)) then
begin
LAttrValue := LNodeElement.Attributes[CAttrName];
Writeln('Attribute value: ' + LAttrValue);
end; { Traverse child nodes }
Writeln(sLineBreak, 'Traversing child nodes...' + sLineBreak);
for I := 0 to LNodeElement.ChildNodes.Count - 1 do
begin
LNode := LNodeElement.ChildNodes.Get(I);
{ Display node name }
Writeln(sLineBreak + 'Node name: ' + LNode.NodeName);
{ Check if the node type is Text. }
if LNode.NodeType = ntText then
begin
Writeln(HTAB + 'This is a node of type Text. The text is: ' + LNode.Text);
end;
{ Check if the node is text element. }
if LNode.IsTextElement then
begin
Writeln(HTAB + 'This is a text element. The text is: ' + LNode.Text);
end;
end;
end;
end;
TXMLDocument use case (Delphi)的更多相关文章
- Delphi中使用TXMLDocument控件应注意的问题 转
Delphi中使用TXMLDocument控件应注意的问题 delphiconstructorxmlclass今天写了一个类,其中用到了TXMLDocument控件.这个控件我是要动态生成的. 但是却 ...
- Delphi中TxmlDocument控件的用法 转
Delphi中对XML文件的解析做的很好,比直接使用MS的MSXML2_TLB中的接口要方便很多,现称述于下面. 在讲之前先给出一个XML实例,在讲某些部分是要结合实例比较容易理解. 1<?xm ...
- Delphi中使用TXMLDocument控件应注意的问题
今天写了一个类,其中用到了TXMLDocument控件.这个控件我是要动态生成的. 但是却遇到了非常奇怪的问题,下面分享一下 procedure TMainForm.Button1Click(Send ...
- delphi中Case语法的使用方法
Case 语句If...Then…Else 语句适合选项较少的情况,如果有很多选项的话利用If 语句就比较麻烦,在这种情况下,Case 语句就容易多了.Case 语句的语法如下: case <表 ...
- Delphi中动态调用TXMLDocument的经历
var vXMLDocument: TXMLDocument;begin vXMLDocument := TXMLDocument.Create('c:/temp/temp.xml'); Cap ...
- Delphi 复习代码
1.取得可文件路径 Path := ExtractFilePath(Application.ExeName); //取得可执行文件路径 TXMLDocument.Create(ExtractFileP ...
- Delphi Xml
用递归方法,使用 xml 文档生成 Treeview 树形视图.由于是动态生成,所以可以通过修改 xml 的逻辑来定制 Treeview 的结构,从而实现了 xml 对 Treeview 的动态配置, ...
- Delphi容器类之---Tlist,TStringlist,THashedStringlist的效率比较
转载自:http://www.ylzx8.cn/windows/delphi/73200.html 本人在做一个测试,服务器是IOCP的,我假定最大链接数是50000个. 测试背景:如果每个链接之间的 ...
- Delphi容器类之---TList、TStringList、TObjectList,以及一个例程的代码分析
转载自:http://blog.csdn.net/jqandjq/article/details/5429137 看了这里标题,大家可能以为我会谈TListBox控件,那就错了.我要谈的是Delphi ...
随机推荐
- Unity 网格 绘制
网格绘制主要用是对Mesh进行操作,通过对vertex和triangles进行操作生成对应的面片: 这里首先得用到一个类:Triangulator(根据vertex生成triangles数组) usi ...
- 001_关于选中的磁盘具有MBR分区表。在 EFI 系统上,Windows 只能安装到 GPT 磁盘。问题解决
问题: 今天我的diy电脑重装系统时,遇到了一个棘手的问题.在选择安装分区的时候,提示有这样的错误. Windows 无法安装到这个磁盘.选中的磁盘具有MBR分区表.在 EFI 系统上,Windows ...
- 原生js实现ajax跨域(兼容IE8,IE9)
html设置meta标签兼容360兼容模式和IE怪异模式 <meta http-equiv="X-UA-Compatible" content="IE=9;IE=8 ...
- 今天我碰到了由于web.xml文件表头信息导致润乾报表启动失败的问题,解决方案如下
下面是从2.3,2.4.2.5 3.0集中版本的web.xml头信息的细节,当发现系统启动不报错但是该生成的功能没有正常生成,特别是在这次配置润乾报表的时候发现用2.4版本的时候,在web.xml中配 ...
- ThinkPHP中的统计查询方法
• count() 表示查询表中总的记录数 • max() 表示查询某个字段的最大值 • min() 表示查询某个字段的最小值 • avg() 表示查询某个字段的平均值 • sum() 表示求出某个字 ...
- java 异常 throw
throw UnsupportedOperationException(); //没有支持的操作NoSuchElementException(); //没有这样的元素
- python3.6连接oracle数据库
下载cx_Oracle模块模块: https://pypi.python.org/pypi/cx_Oracle/5.2.1#downloads 这里下载的是源码进行安装 [root@oracle or ...
- ***文件上传控件bootstrap-fileinput的使用和参数配置说明
特别注意: 引入所需文件后页面刷新查看样式奇怪,浏览器提示错误等,可能是因为js.css文件的引用顺序问题,zh.js需要在fileinput.js后面引入.bootstrap最好在filein ...
- CentOS下Lua 环境的搭建
curl -R -O http://www.lua.org/ftp/lua-5.2.2.tar.gz .tar.gz cd lua- make linux test 报错 cd src &&a ...
- Java中的String问题
方式一:String a = “aaa” ; 方式二:String b = new String(“aaa”); 两种方式都能创建字符串对象,但方式一要比方式二更优.因为字符串是保存在常量池中的,而通 ...