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;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
{必须用万一提供的 xml 测试文件, 才能有相同的返回值}
end;
//获取节点名称
procedure TForm1.Button1Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
ShowMessage(node.NodeName); {科室名单}
node := node.ChildNodes[0]; {XMLDocument1.DocumentElement.ChildNodes[0]}
ShowMessage(node.NodeName); {人员}
node := node.ChildNodes[0]; {XMLDocument1.DocumentElement.ChildNodes[0].ChildNodes[0]}
ShowMessage(node.NodeName); {姓名}
end;
//获取属性名称
procedure TForm1.Button2Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
ShowMessage(node.AttributeNodes[0].NodeName); {备注}
node := node.ChildNodes[0]; {XMLDocument1.DocumentElement.ChildNodes[0]}
ShowMessage(node.AttributeNodes[0].NodeName); {职务}
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;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//打开
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('c:\temp\test.xml');
{必须用万一提供的 xml 测试文件, 才能有相同的返回值}
end;
//获取节点名称
procedure TForm1.Button1Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
ShowMessage(node.NodeName); {科室名单}
node := node.ChildNodes[0]; {XMLDocument1.DocumentElement.ChildNodes[0]}
ShowMessage(node.NodeName); {人员}
node := node.ChildNodes[0]; {XMLDocument1.DocumentElement.ChildNodes[0].ChildNodes[0]}
ShowMessage(node.NodeName); {姓名}
end;
//获取属性名称
procedure TForm1.Button2Click(Sender: TObject);
var
node: IXMLNode;
begin
node := XMLDocument1.DocumentElement;
ShowMessage(node.AttributeNodes[0].NodeName); {备注}
node := node.ChildNodes[0]; {XMLDocument1.DocumentElement.ChildNodes[0]}
ShowMessage(node.AttributeNodes[0].NodeName); {职务}
end;
end.
-----------------------------------------------------------------------------------------------------------------------------------
出处:http://www.cnblogs.com/del/archive/2008/01/03/1024577.html
作者:黄聪
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。