TXMLDocument 的使用

TXMLDocument是DELPHI自带的操作XML的类。

需要它,需要引用单元: uses XMLDoc;

var
XMLDoc:TXMLDocument;
XMLNode: IXMLNode;
child: IXMLNode;
begin
CoInitialize(nil); //初始化ActiveX
XMLDoc:=TXMLDocument.Create(self);
XMLDoc.Active := true;
XMLNode := XMLDoc.AddChild('ConsumeRec');
child := XMLNode.AddChild('EventsDateTime');
child.Text := dateTostr(Now);
XMLDoc.SaveToFile('c:\ok.xml');
XMLDoc.Free; //不能用,因为接口自动释放内存。
CoUninitialize;
end;

  动态创建TXMLDocument对XML文件进行读取和写入

var
XML : TXMLDocument;
Node1 : IXMLNode;
DocIntf : IXMLDocument;
begin
XML := TXMLDocument.Create(self);
DocIntf := XML; //防止接口被自动释放,少了这一句会发生AV
try
XML.LoadFromStream(Strem);
XML.Active := True;
{ 读ReportObject属性 }
Node1 := XML.DocumentElement.ChildNodes.FindNode('ReportObjectProperty');
ReportName := Node1.ChildNodes.FindNode('ReportName').GetAttributeNS('Value', '');
ReportType := Node1.ChildNodes.FindNode('ReportType').GetAttributeNS('Value', '');
DataViewName := Node1.ChildNodes.FindNode('DataViewName').GetAttributeNS('Value', '');
SQLStr := Node1.ChildNodes.FindNode('SQLStr').GetAttributeNS('Value', '');
finally
XML := nil;
DocIntf := nil;
end;
end;

  

TXMLDocument 的使用的更多相关文章

  1. Delphi中使用TXMLDocument控件应注意的问题 转

    Delphi中使用TXMLDocument控件应注意的问题 delphiconstructorxmlclass今天写了一个类,其中用到了TXMLDocument控件.这个控件我是要动态生成的. 但是却 ...

  2. Delphi中TxmlDocument控件的用法 转

    Delphi中对XML文件的解析做的很好,比直接使用MS的MSXML2_TLB中的接口要方便很多,现称述于下面. 在讲之前先给出一个XML实例,在讲某些部分是要结合实例比较容易理解. 1<?xm ...

  3. TXMLDocument换行的两种方案

    手写代码:   XML格式化使用msxml引擎,Delphi代码如下: Delphi/Pascal code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  4. Delphi中使用TXMLDocument控件应注意的问题

    今天写了一个类,其中用到了TXMLDocument控件.这个控件我是要动态生成的. 但是却遇到了非常奇怪的问题,下面分享一下 procedure TMainForm.Button1Click(Send ...

  5. TXMLDocument 创建空值节点不要缩写

    TXMLDocument 创建空值节点不要缩写 xmldoc.CreateNode('input'); 然后访问 xmldoc.DocumentElement.XML <input/> 节 ...

  6. XPath and TXmlDocument

    XML example, from the OmniXML XPath demo: <?xml version="1.0" encoding="UTF-8" ...

  7. TXMLDocument use case (Delphi)

    Description This example illustrates the basic operations on an XML document. Code procedure CreateD ...

  8. Using TXMLDocument, Working with XML Nodes

    Using TXMLDocument The starting point for working with an XML document is the Xml.XMLDoc.TXMLDocumen ...

  9. Lazarus Reading XML- with TXMLDocument and TDOMNode

    这里读取'HistoryPath' ,'TracePath' 元素下的‘value’属性使用的是 var xmlCfg: TXMLDocument; .... function ReadXMLCFG: ...

  10. Delphi中动态调用TXMLDocument的经历

    var  vXMLDocument: TXMLDocument;begin  vXMLDocument := TXMLDocument.Create('c:/temp/temp.xml');  Cap ...

随机推荐

  1. sql server统计总成绩和排名

    这里的图片可以拖拽到一个新页面查看原图!!!! 这里有两个表,需要查询总成绩和排名 Sql语句: select ST.name,SE.Chinese,SE.Math,SE.English, ( SE. ...

  2. SDL -安全开发生命周期

    1.学习SDL https://www.cnblogs.com/whoami101/p/9914862.html 2.学习SDL https://blog.csdn.net/whatday/artic ...

  3. Haddop完全分布式集群搭建

    hadoop完全分布式搭建 建议(遇到的坑): 如果自己用的操作系统就是linux,我本身是deepin系统,装了两台虚拟机,结果,用户名没有配置,导致启动不了,因为hadoop的master节点启动 ...

  4. 异常-Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): Permission denied: user=hdfs, access=WRITE, inode="/hbase":root:supergroup:drwxr-xr-x

    1 详细异常 Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlExce ...

  5. Bash基础——printf

    简介 printf将参数插入到用户定义的文本字符串中,从而创建格式化的输出.printf将格式化的字符串输出到标准输出.printf命令根源是C语言下面的printf函数,就连名字都一样,很多用法也是 ...

  6. C++——调用优化

    原始代码 #include<iostream> using namespace std; class Test { public: //以参数列表形式对数据成员进行初始化 Test() : ...

  7. idou老师教你学istio30:Mixer Redis Quota Adapter 实现和机制

    1. 配置 1.1参数 1.2 Params.Quota 1.3Params.Override 1.4Params.QuotaAlgorithm 速率限制的算法: Fixed Window 算法每个时 ...

  8. 链表实现队列(python)

    # -*- coding: utf-8 -*- from collections import deque class Node(object): def __init__(self, value=N ...

  9. redis在本地进行启动的方式

    第一种 使用cmd命令行进行过操作 在本地配置好redis之后,启动的话是比较简单的 1-首先打开cmd运行界面 2-定位到本地redis目录 3-运行命令redis-server.exe redis ...

  10. P2P system: Chord

    DHT= Distributed Hash Table store the objects(files) at nodes (hosts, machines) in a cluster. The cl ...