点击这里:Delphi 中的 XMLDocument 类详解(11) - 一个多余的属性: Nodes

unit Unit1; 
 
erface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls; 
 
type 
 TForm1 = (TForm) 
  XMLDocument1: TXMLDocument; 
  Button1: TButton; 
  procedure FormCreate(Sender: TObject); 
  procedure Button1Click(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; 
 
 
//个多余属性: Nodes 
procedure TForm1.Button1Click(Sender: TObject); 
var 
 node: IXMLNode; 
begin 
 node := XMLDocument1.DocumentElement.ChildNodes[0]; 
 
 ShowMessage(node.ChildNodes[0].NodeValue);      {张 3} 
 ShowMessage(node.ChildNodes.Nodes[0].NodeValue);   {张 3} 
 
 ShowMessage(node.AttributeNodes[0].NodeValue);    {科长} 
 ShowMessage(node.AttributeNodes.Nodes[0].NodeValue); {科长} 
end; 
 
end. 
 
 
{ 
 既然可以使用 ChildNodes[0].NodeValue 访问, 又何必存在 ChildNodes.Nodes[0].NodeValue 呢? 
 其实真正存在是后者, 前者是后者种默认访问方式. 
} 


Tags:  .netxmldocument 点击这里

延伸阅读

最新评论

发表评论