给你个例子 D7/XP下通过测试<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ComCtrls, xmldom, XMLIntf, msxmldom, XMLDoc;<br><br>type<br> TChannelList = class(TForm)<br> ChannelList: TListView;<br> Button: TButton;<br> SLXMLDocument: TXMLDocument;<br> Label1: TLabel;<br> procedure ChannelListAdvancedCustomDrawItem(Sender: TCustomListView;<br> Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;<br> var DefaultDraw: Boolean);<br> procedure FormShow(Sender: TObject);<br> procedure ButtonClick(Sender: TObject);<br> private<br> { Private declarations }<br><br> procedure ShowList;<br> public<br> { Public declarations }<br> end;<br><br>var<br> ChannelList: TChannelList;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TChannelList.ChannelListAdvancedCustomDrawItem(<br> Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;<br> Stage: TCustomDrawStage; var DefaultDraw: Boolean);<br>begin<br> if Item.Index mod 2 = 1 then<br> Sender.Canvas.Brush.Color:=clMoneyGreen<br> else<br> Sender.Canvas.Brush.Color:=clMenuHighlight;<br>end;<br><br>procedure TChannelList.FormShow(Sender: TObject);<br>begin<br> ShowList;<br>end;<br><br>procedure TChannelList.ButtonClick(Sender: TObject);<br>begin<br> ChannelList.Clear;<br> ShowList;<br>end;<br><br>procedure TChannelList.ShowList;<br>var<br> FilePath, TmpStr_A, TmpStr_B: String;<br> Root, Parent_Node, Child_node: IXMLNode;<br>begin<br> FilePath:= ExtractFilePath(application.ExeName) + 'ChannelList.XML';<br> if(Not FileExists(FilePath)) then<br> ShowMessage('“ChannelList.XML”未找到')<br> else<br> begin<br> SLXMLDocument.LoadFromFile(FilePath);<br> Root:=SLXMLDocument.DocumentElement;<br> Parent_Node := Root.ChildNodes.First;<br> while (Parent_Node <> Nil) do<br> begin<br> if (Parent_Node.NodeName = 'channel') then<br> begin<br> Child_Node := Parent_Node.ChildNodes.First;<br> TmpStr_A:=''; TmpStr_B:='KaoKao';<br> while (Child_Node <> nil) do<br> begin<br> if (Child_Node.NodeName = 'ChannelName') then<br> TmpStr_A:=Child_Node.Text;<br> if (Child_Node.NodeName = 'ProgramList2') then<br> begin<br> TmpStr_B:=Child_Node.Text;<br> if TmpStr_B='' then<br> TmpStr_B:='无节目列表';<br> end;<br> if (TmpStr_A<>'') and (TmpStr_B<>'KaoKao')then<br> begin<br> With ChannelList.Items.Add do<br> begin<br> Caption:=TmpStr_A;<br> SubItems.Add(TmpStr_B);<br> end;<br> Break;<br> end;<br> Child_Node := Child_Node.NextSibling;<br> end;<br> end;<br> Parent_Node := Parent_Node.NextSibling;<br> end;<br> end;<br> Label1.Caption := Format('用有 %d 个频道', [ChannelList.Items.Count-1]);<br>end;<br><br>end.