Delphi 中的 XMLDocument 类详解(4) - 获取根目录下的元素数

 Unit1;




  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;


  TForm1 = (TForm)
    XMLDocument1: TXMLDocument;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
     FormCreate(Sender: TObject);
     Button1Click(Sender: TObject);
     Button2Click(Sender: TObject);
     Button3Click(Sender: TObject);
  
    
  
    
  ;


  Form1: TForm1;






 TForm1.FormCreate(Sender: TObject);

  XMLDocument1.LoadFromFile();
;



 TForm1.Button1Click(Sender: TObject);

  ShowMessage(IntToStr(XMLDocument1.DocumentElement.ChildNodes.Count)); 
  
  
;



 TForm1.Button2Click(Sender: TObject);

  nodeList: IXMLNodeList; 

  nodeList := XMLDocument1.DocumentElement.ChildNodes;
  

  ShowMessage(IntToStr(nodeList.Count)); 
;



 TForm1.Button3Click(Sender: TObject);

  node: IXMLNode;         
  nodeList: IXMLNodeList; 

  node := XMLDocument1.DocumentElement;
  

  nodeList := node.ChildNodes;
  ShowMessage(IntToStr(nodeList.Count)); 
;

.

posted on 2015-04-10 00:53  martian6125  阅读(150)  评论(0编辑  收藏  举报