Delphi 中的 XMLDocument 类详解(13) - 关于 XML 属性
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;
type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
{必须用万一提供的 xml 测试文件, 才能有相同的返回值}
end;
//XMLDocument1 对象的 XML 属性
procedure TForm1.Button1Click(Sender: TObject);
begin
{前面我们经常用这句话, 因为这里的 Lines 与 XML 同属于 TStrings}
Memo1.Lines := XMLDocument1.XML;
{如果不怕麻烦, 这样写也可以:}
Memo1.Lines.Text := XMLDocument1.XML.Text;
{如果知道了这一点, 那 XML 属性的功能可就多了, 并且这里的 XML 属性是可写的}
{不过这里要谈的是节点的 XML 属性}
end;
//根节点的 XML 属性
procedure TForm1.Button2Click(Sender: TObject);
var
node: IXMLNode;
begin
{先看根节点: XMLDocument1.DocumentElement}
node := XMLDocument1.DocumentElement;
//Memo1.Lines := node.XML; {这一句会出错}
{因为节点的 XML 属性是 WideString 类型的, 应该这样:}
Memo1.Lines.Text := node.XML; {将会读出根节点与根节点包含的所有内容}
{还有一个更大的区别: 节点的 XML 是只读的!}
end;
//子节点的 XML 属性
procedure TForm1.Button3Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.ChildNodes[0];
Memo1.Lines.Text := node.XML; {会显示一个子节点的全部}
end;
//属性的 XML 属性
procedure TForm1.Button4Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.AttributeNodes[0]; {属性也是 IXMLNode 类型的}
ShowMessage(node.NodeName); {备注}
ShowMessage(node.NodeValue); {测试}
{用 XML 属性一次把他们都读出来:}
ShowMessage(node.XML); {备注="测试"}
end;
//叶节点的 XML 属性
procedure TForm1.Button5Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.ChildNodes[0];
node := node.ChildNodes[0];
node := node.ChildNodes[0]; {这就是叶节点了}
ShowMessage(node.XML); {张三}
{这时的 XML 属性和 Text 属性一样了}
ShowMessage(node.Text); {张三}
end;
end.
Delphi 中的 XMLDocument 类详解(13) - 关于 XML 属性
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;
type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
{必须用万一提供的 xml 测试文件, 才能有相同的返回值}
end;
//XMLDocument1 对象的 XML 属性
procedure TForm1.Button1Click(Sender: TObject);
begin
{前面我们经常用这句话, 因为这里的 Lines 与 XML 同属于 TStrings}
Memo1.Lines := XMLDocument1.XML;
{如果不怕麻烦, 这样写也可以:}
Memo1.Lines.Text := XMLDocument1.XML.Text;
{如果知道了这一点, 那 XML 属性的功能可就多了, 并且这里的 XML 属性是可写的}
{不过这里要谈的是节点的 XML 属性}
end;
//根节点的 XML 属性
procedure TForm1.Button2Click(Sender: TObject);
var
node: IXMLNode;
begin
{先看根节点: XMLDocument1.DocumentElement}
node := XMLDocument1.DocumentElement;
//Memo1.Lines := node.XML; {这一句会出错}
{因为节点的 XML 属性是 WideString 类型的, 应该这样:}
Memo1.Lines.Text := node.XML; {将会读出根节点与根节点包含的所有内容}
{还有一个更大的区别: 节点的 XML 是只读的!}
end;
//子节点的 XML 属性
procedure TForm1.Button3Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.ChildNodes[0];
Memo1.Lines.Text := node.XML; {会显示一个子节点的全部}
end;
//属性的 XML 属性
procedure TForm1.Button4Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.AttributeNodes[0]; {属性也是 IXMLNode 类型的}
ShowMessage(node.NodeName); {备注}
ShowMessage(node.NodeValue); {测试}
{用 XML 属性一次把他们都读出来:}
ShowMessage(node.XML); {备注="测试"}
end;
//叶节点的 XML 属性
procedure TForm1.Button5Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.ChildNodes[0];
node := node.ChildNodes[0];
node := node.ChildNodes[0]; {这就是叶节点了}
ShowMessage(node.XML); {张三}
{这时的 XML 属性和 Text 属性一样了}
ShowMessage(node.Text); {张三}
end;
end.
Delphi 中的 XMLDocument 类详解(13) - 关于 XML 属性
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;
type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
{必须用万一提供的 xml 测试文件, 才能有相同的返回值}
end;
//XMLDocument1 对象的 XML 属性
procedure TForm1.Button1Click(Sender: TObject);
begin
{前面我们经常用这句话, 因为这里的 Lines 与 XML 同属于 TStrings}
Memo1.Lines := XMLDocument1.XML;
{如果不怕麻烦, 这样写也可以:}
Memo1.Lines.Text := XMLDocument1.XML.Text;
{如果知道了这一点, 那 XML 属性的功能可就多了, 并且这里的 XML 属性是可写的}
{不过这里要谈的是节点的 XML 属性}
end;
//根节点的 XML 属性
procedure TForm1.Button2Click(Sender: TObject);
var
node: IXMLNode;
begin
{先看根节点: XMLDocument1.DocumentElement}
node := XMLDocument1.DocumentElement;
//Memo1.Lines := node.XML; {这一句会出错}
{因为节点的 XML 属性是 WideString 类型的, 应该这样:}
Memo1.Lines.Text := node.XML; {将会读出根节点与根节点包含的所有内容}
{还有一个更大的区别: 节点的 XML 是只读的!}
end;
//子节点的 XML 属性
procedure TForm1.Button3Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.ChildNodes[0];
Memo1.Lines.Text := node.XML; {会显示一个子节点的全部}
end;
//属性的 XML 属性
procedure TForm1.Button4Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
node := node.AttributeNodes[0]; {属性也是 IXMLNode 类型的}
ShowMessage(node.NodeName); {备注}
ShowMessage(node.NodeValue); {测试}
{用 XML 属性一次把他们都读出来:}
ShowMessage(node.XML); {备注="测试"}
end;
//叶节点的 XML 属性
procedure TForm1.Button5Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XM
没有合适的资源?快使用搜索试试~ 我知道了~
delphi XML XMLDocument 文档 里面全是源码加备注
共22个文件
txt:22个
3星 · 超过75%的资源 需积分: 31 21 下载量 15 浏览量
2013-08-22
15:45:35
上传
评论
收藏 19KB RAR 举报
温馨提示
delphi XML XMLDocument 文档 里面全是源码加备注
资源推荐
资源详情
资源评论
收起资源包目录
delphi XML XMLDocument.rar (22个子文件)
delphi XML XMLDocument
5.获取元素内容.txt 3KB
15.创建与保存 xml.txt 2KB
13.关于 XML 属性.txt 16KB
8.添加与删除节点.txt 2KB
9.HasChildNodes 与 IsTextElement.txt 4KB
11. Nodes .txt 1KB
14.遍历 XML 文件.txt 3KB
网站.txt 58B
0.xml 语法提示.txt 619B
20.动态建立 XMLDocument 对象 .txt 1KB
18.更好地显示 xml 的测试结果 - FormatXMLData 及其他.txt 2KB
7.获取节点名称与节点的属性名称.txt 2KB
10.判断节点类型 支节点、叶节点、文本节点、空节点.txt 2KB
3.读取 xml 文件.txt 2KB
6.访问节点属性.txt 3KB
12.读取或设置 xml 的编码与版本号.txt 810B
16.节点列表中的第一个与最后一个节点.txt 1KB
17.上一个节点、下一个节点、父节点.txt 1KB
2.记要 .txt 525B
4.获取根目录下的元素数.txt 2KB
1.等待研究的内容 .txt 2KB
19.NodeValue 与 NodeName 的读写区别.txt 2KB
共 22 条
- 1
资源评论
- mokmok2322022013-08-26XML的一些操作说明,并没有源码,不过是值得下载的资源,
小威哥
- 粉丝: 0
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功