如何读取RSS生成新闻列表,我是用Delphi做一个客户端的新闻列表,要读取RSS文件来实现,以前没接触过这方面的技术,请各位大侠指点一二,我是不是要用XML控件进行读取呢?由于刚接触,没什么思路,弄明白就结贴给分,谢谢各位大侠了~~
顶者也有分哦~~

解决方案 »

  1.   

    就是下载一个xml文件解析出数据就形成了新闻列表function GetRssInfo(const FeedUrl: string): Boolean;
    var
      VXMLDoc: IXMLDocument;
      VNode: IXMLNode;
      TempV: OleVariant;
      i, NodeCount: Integer;
    begin
      Result := False;  if Trim(FeedUrl) = '' then
        Exit;  VXMLDoc := TXMLDocument.Create(Application.MainForm);
      try
        try
          VXMLDoc.FileName := FeedUrl;
          VXMLDoc.Active := True;      VNode := VXMLDoc.DocumentElement.ChildNodes['channel'];
          NodeCount := VNode.ChildNodes.Count - 1;
          SetLength(GlobalData.ItemTitle, NodeCount);
          SetLength(GlobalData.ItemLink, NodeCount);
          SetLength(GlobalData.ItemDescription, NodeCount);
          SetLength(GlobalData.ItemPubDate, NodeCount);
          GlobalData.ItemCount := 0;      GlobalData.RootTitle := VNode.ChildNodes['title'].NodeValue;
          for i := 0 to NodeCount do
          begin
            if VNode.ChildNodes[i].NodeName = 'item' then
            begin
              TempV := VNode.ChildNodes[i].ChildNodes['title'].NodeValue;
              if TempV = null then
                TempV := '没有标题';
              GlobalData.ItemTitle[GlobalData.ItemCount] := TempV;          TempV := VNode.ChildNodes[i].ChildNodes['link'].NodeValue; ;
              if TempV = null then
                TempV := 'http://www.ftpff.com';
              GlobalData.ItemLink[GlobalData.ItemCount] := TempV;          TempV := VNode.ChildNodes[i].ChildNodes['description'].NodeValue;
              if TempV = null then
                TempV := '没有摘要';
              GlobalData.ItemDescription[GlobalData.ItemCount] := TempV;          TempV := VNode.ChildNodes[i].ChildNodes['pubDate'].NodeValue;
              if TempV = null then
                TempV := '1985-06-29';
              GlobalData.ItempubDate[GlobalData.ItemCount] := TempV;          inc(GlobalData.ItemCount);
              result := true;
            end;
          end;
        except
          showmessage('无法获取!')
        end;
      finally
        VXMLDoc := nil;
      end;
    end;