delphi XML简单处理
2024-10-18 22:29:49
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Xml.XMLDoc, Xml.xmldom, Xml.XMLIntf,
Vcl.StdCtrls; type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
IDoc: IXMLDocument;
Root, N1, N2, N3: IXMLNode;
I: Integer;
begin
IDoc := TXMLDocument.Create(nil);
IDoc.Active := True;
Root := IDoc.AddChild('公司');
for I := to do
begin
N1 := Root.AddChild('部门');
N1.Attributes['Id'] := I;
N1.AddChild('名称').NodeValue := '部门_'+I.ToString;
N1.AddChild('主管').NodeValue := '主管_'+I.ToString;
end;
IDoc.SaveToFile('d:\jjw.xml');
end; procedure TForm1.Button2Click(Sender: TObject);
var
Doc: IXMLDocument;
Node: IXMLNode;
I: Integer;
begin
Doc := TXMLDocument.Create(nil);
Doc.LoadFromFile('d:\jjw.xml');
Doc.Active := True;
Node := Doc.DocumentElement;
for I := to Node.ChildNodes.Count- do
Node.ChildNodes[I].AddChild('人数').NodeValue := IntToStr(I+);
Doc.SaveToFile('d:\jjw.xml');
end; procedure TForm1.Button3Click(Sender: TObject);
var
Doc: IXMLDocument;
Node: IXMLNode;
I: Integer;
begin
Doc := TXMLDocument.Create(nil);
Doc.LoadFromFile('d:\jjw.xml');
Doc.Active := True;
Node := Doc.DocumentElement;
for I := to Node.ChildNodes.Count- do
Node.ChildNodes[I].ChildNodes.Delete();
Doc.SaveToFile('d:\jjw.xml');
end; procedure TForm1.Button4Click(Sender: TObject);
var
Doc: IXMLDocument;
Root, Node: IXMLNode;
I: Integer;
begin
Doc := TXMLDocument.Create(nil);
Doc.LoadFromFile('d:\jjw.xml');
Doc.Active := True;
Root := Doc.DocumentElement;
for I := to Root.ChildNodes.Count- do
begin
Node := Root.ChildNodes[I];
if Node.Attributes['Id']= then
Node.ChildNodes[].NodeValue := ;
end;
Doc.SaveToFile('d:\jjw.xml');
end; end.
最新文章
- Android高手速成--第三部分 优秀项目
- Servlet基础(一) Servlet简介 关键API介绍及结合源码讲解
- cocos2dx 3.7中 AppDelegate.h的class TestController;这种写法的具体意思不太明白,只能猜是类似于外部定义的东西。
- 案例分析——BAT业务https化经历
- 【集训第三天·疯狂训练】哦,顺带学习了manacher
- app控件唯一相对Xpath自动生成(增强版uiautomatorviewer)
- 我的第一个python web开发框架(39)——后台接口权限访问控制处理
- STM32进入HardFault_Handler处理办法
- fabric读书笔记
- Windows Phone本地数据库(SQLCE):4、[Column]attribute(翻译) (转)
- matplot 代码实例2
- 移动前端兼容性笔记 - 安卓2.x 自带原生浏览器箭头问题
- /etc/default/useradd配置文件详解
- ExtJS ComboBox同时加载远程和本地数据
- Docker安装及常用操作
- hint指定index的深入理解
- IDHTTP用法详解 good
- Java 实现桥接(Bridge)模式
- js判断object的具体类型(或者说判断object的类class)
- User-defined types
热门文章
- Promise使用
- MDK编译过程
- hdoj5769后缀自动机版本
- Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)D. Frequency of String
- leetcode-956. 最高的广告牌
- 关于wincc与博图的安装问题
- laravel5.5 调用系统自带登陆认证auth
- SQL DELETE 语句详解
- mysql InnoDB index 主键采用聚簇索引,二级索引不采用聚簇索引
- 查看shell 命令 路径