delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
求像数据集一样循环遍历XML的方法 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiNetwork/html/delphi_20061218092101103.html
<?xml   version="1.0"   encoding="GB2312"?>  
  <w   st="1">  
      <w1   c1="0"   c2=""   c3="0"   c4=""   c5="0"   c6=""   c7="0"   c8=""   c9="4.843011"   c10="21.00"   c11="0"   c12=""   c13="0"   c14=""   c15="0"   c16=""   h="费耶诺德"   a="海牙"   gt="2006-12-10   19:30"   gn="荷甲"   st="4"/>  
      <w2   c1="0"   c2=""   c3="0"   c4=""   c5="0"   c6=""   c7="0"   c8=""   c9="5.451286"   c10="18.00"   c11="0"   c12=""   c13="0"   c14=""   c15="0"   c16=""   h="阿贾克斯"   a="阿尔克马尔"   gt="2006-12-10   19:30"   gn="荷甲"   st="4"/>  
      <w3   c1="0"   c2=""   c3="0"   c4=""   c5="3.571144"   c6="28.00"   c7="0"   c8=""   c9="0"   c10=""   c11="0"   c12=""   c13="0"   c14=""   c15="0"   c16=""   h="杜伊斯堡"   a="  
  </w>  
   
   
   
  var  
      Clinic:   IXMLNode;  
  begin  
  XMLDocument1.Active   :=   true;  
   
  ????  
      Clinic   :=   XMLDocument1.DocumentElement.ChildNodes[0].;  
      caption   :=   Clinic.AttributeNodes.Nodes['c1'].Text;  
  ????  
  end;  
   
 

这样的能行吗

var  
      var  
      Node,childNode:IXMLNode;  
      xmlDoc:IXMLDocument;  
      i:integer;  
       
  begin  
      CoInitialize(nil);  
      xmlDoc   :=   NewXMLDocument   ;  
        xmlDoc.Active:=true;  
        xmlDoc.loadFromXML(YourXMLString);  
        Node:=xmlDoc.ChildNodes.FindNode('w');  
        for   i:=0   to   Node.ChildNodes.Count-1   do    
  begin    
        childnode:=Node.ChildNodes[i];  
        //do   your   work  
   
  end;  
      XMLDoc   :=   nil;  
      CoUninitialize();  
  end;

其实就跟你treeview加载进去的树型结构是一样的道理啊    
  AddChild   加节点   Attributes加节点的属性

列如把listview的ITEM加载进去成XML的函数  
  function   GetxmlNode:   string;  
  var  
      nmm_ss:   string;  
      nmm_inti:   Integer;  
      nmm_xmldoc:   TXMLDocument;  
      root:   IXMLNode;  
      nmm_xmlnode:   IXMLNode;  
  begin  
      nmm_xmldoc   :=   TXMLDocument.Create(Self);  
      nmm_xmldoc.LoadFromFile(nmg_strpath   +   'UpdateFree.xml');  
      root   :=   nmm_xmldoc.DocumentElement;  
      root   :=   root.ChildNodes.First;  
      root.ChildNodes.Clear;  
      for   nmm_inti   :=   0   to   ListView1.Items.Count   -   1   do  
      begin  
          nmm_xmlnode   :=   root.AddChild('file');  
          nmm_xmlnode.Attributes['name']   :=   ListView1.Items[nmm_inti].SubItems.Strings[0];  
          nmm_xmlnode.Attributes['version']   :=   ListView1.Items[nmm_inti].SubItems.Strings[1];  
          nmm_xmlnode.Attributes['dest']   :=   ListView1.Items[nmm_inti].SubItems.Strings[2];  
          nmm_xmlnode.Attributes['time']   :=   ListView1.Items[nmm_inti].SubItems.Strings[3];  
      end;  
      nmm_xmldoc.SaveToFile(nmg_strpath   +   'UpdateFree.xml');  
      nmm_xmldoc.Free;  
  end;

posted on 2008-10-28 09:56 delphi2007 阅读(318) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。