unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;
type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('test.xml');
end;
//获取根目录下的元素数(1)
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(XMLDocument1.DocumentElement.ChildNodes.Count)); {4}
{DocumentElement 是根节点}
{ChildNodes 是节点包含的子节点的列表}
end;
//获取根目录下的元素数(2)
procedure TForm1.Button2Click(Sender: TObject);
var
nodeList: IXMLNodeList; {定义一个节点列表对象}
begin
nodeList := XMLDocument1.DocumentElement.ChildNodes;
{把根节点下的子节点列表赋给节点列表对象}
ShowMessage(IntToStr(nodeList.Count)); {4}
end;
//获取根目录下的元素数(3)
procedure TForm1.Button3Click(Sender: TObject);
var
node: IXMLNode; {定义一个节点对象}
nodeList: IXMLNodeList; {定义一个节点列表对象}
begin
node := XMLDocument1.DocumentElement;
{根节点也是一个节点, 把它赋给节点对象}
nodeList := node.ChildNodes;
ShowMessage(IntToStr(nodeList.Count)); {4}
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;
type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('test.xml');
end;
//获取根目录下的元素数(1)
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(XMLDocument1.DocumentElement.ChildNodes.Count)); {4}
{DocumentElement 是根节点}
{ChildNodes 是节点包含的子节点的列表}
end;
//获取根目录下的元素数(2)
procedure TForm1.Button2Click(Sender: TObject);
var
nodeList: IXMLNodeList; {定义一个节点列表对象}
begin
nodeList := XMLDocument1.DocumentElement.ChildNodes;
{把根节点下的子节点列表赋给节点列表对象}
ShowMessage(IntToStr(nodeList.Count)); {4}
end;
//获取根目录下的元素数(3)
procedure TForm1.Button3Click(Sender: TObject);
var
node: IXMLNode; {定义一个节点对象}
nodeList: IXMLNodeList; {定义一个节点列表对象}
begin
node := XMLDocument1.DocumentElement;
{根节点也是一个节点, 把它赋给节点对象}
nodeList := node.ChildNodes;
ShowMessage(IntToStr(nodeList.Count)); {4}
end;
end.
-----------------------------------------------------------------------------------------------------------------------------------------------
出处:http://www.cnblogs.com/del/archive/2008/01/03/1024407.html
作者:黄聪
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。