Delphi 中的 XMLDocument 类详解(5) - 获取元素内容

 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;
    Button4: TButton;
     FormCreate(Sender: TObject);
     Button1Click(Sender: TObject);
     Button2Click(Sender: TObject);
     Button3Click(Sender: TObject);
     Button4Click(Sender: TObject);
  
    
  
    
  ;


  Form1: TForm1;






 TForm1.FormCreate(Sender: TObject);

  XMLDocument1.LoadFromFile();
  
;



 TForm1.Button1Click(Sender: TObject);

  ShowMessage(XMLDocument1.DocumentElement.ChildNodes[].ChildNodes[].Text); 
  ShowMessage(XMLDocument1.DocumentElement.ChildNodes[].ChildNodes[].Text); 
  ShowMessage(XMLDocument1.DocumentElement.ChildNodes[].ChildNodes[].Text); 
  
  
  
  
  ShowMessage(XMLDocument1.DocumentElement.ChildNodes[].ChildNodes[].Text); 
;



 TForm1.Button2Click(Sender: TObject);

  nodeList: IXMLNodeList;
  node: IXMLNode;

  nodeList := XMLDocument1.DocumentElement.ChildNodes;
  node := nodeList[];

  ShowMessage(node.ChildNodes[].Text); 
  ShowMessage(node.ChildNodes[].Text); 
  ShowMessage(node.ChildNodes[].Text); 
;



 TForm1.Button3Click(Sender: TObject);

  nodeList: IXMLNodeList;
  node: IXMLNode;
  num,i: Integer;

  nodeList := XMLDocument1.DocumentElement.ChildNodes;
  num := nodeList.Count;

   i :=   num -  
  
    node := nodeList[i];
    ShowMessage(node.ChildNodes[].Text); 
  ;
;



 TForm1.Button4Click(Sender: TObject);

  nodeList: IXMLNodeList;
  node: IXMLNode;
  num,i: Integer;

  nodeList := XMLDocument1.DocumentElement.ChildNodes;
  num := nodeList.Count;

   i :=   num -  
  
    node := nodeList[i];
    ShowMessage(node.ChildValues[]); 
  ;
;

.

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