⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urssfeed.pas

📁 自己写的一个 RSS 阅读器
💻 PAS
字号:
unit uRSSFeed;

interface

uses Classes, uW3CDTF, FastStringFuncs, uRssBase, MSXML2_TLB,
  IniFiles, uConstants;

type

TRSSFeed = class(TInterfacedObject, IRSSBase)
private
  FDoc:IXMLDOMDocument2;
	fItems : IRSSItemBaseList;
  FTitle, FDescription : string;
  FVersion, FLink, FCreator : WideString;
protected
  function Get_Version : WideString;
  function Get_Title : string;
  function Get_Link: WideString;
  function Get_Description: string;
  function Get_Creator: WideString;
  function Get_Items: IRSSItemBaseList;
public
	constructor Create(theDoc : IXMLDOMDocument2);
  property Items:IRSSItemBaseList read fItems;
  property Version: WideString read Get_Version;
  property Title: string read Get_Title;
  property Link: Widestring read Get_Link;
  property Description: string read Get_Description;
  property Creator: WideString read Get_Creator;
end;

TRSSItems = class(TInterfacedObject, IRSSItemBaseList)
private
  fItems : THashedStringList;
  fNode:IXMLDOMNode;
protected
  procedure Add(item : TInterfacedObject);
  function Get_Item(index : integer): IRSSItemBase;
  function Get_Count(): integer;
public
	constructor Create(theNode:IXMLDOMNode);

end;

TRSSItem = class(TInterfacedObject, IRSSItemBase)
  private
    FNode:IXMLDOMNode;
    FFeedTitle:string;
    FAuthor: string;
    FTitle: string;
    FPubDate: TW3CDTF;
    FGuid: WideString;
    FLink: WideString;
    FDescription: string;
    FCategory : string;
  protected
    function Get_Author: string;
    function Get_Title: string;
    function Get_PubDate: TW3CDTF;
    function Get_Guid: WideString;
    function Get_Link: WideString;
    function Get_Category: string;
    function Get_Creator: WideString;
    function Get_Description: string;
  public
		constructor Create(theNode : IXmlDOMNode);
    property PubDate: TW3CDTF read Get_PubDate;
    property Title: string read Get_Title;
    property Link: WideString read Get_Link;
    property Guid: WideString read Get_Guid;
    property Description: string read Get_Description;
    property Author: string read Get_Author;
    property Category: string read Get_Category;
    property Creator: WideString read Get_Creator;
  end;

function GetRSSFeed(Doc: IXMLDOMDocument2): IRSSBase;


implementation

uses SysUtils, ComObj;

function GetRSSFeed(Doc: IXMLDOMDocument2): IRSSBase;
begin
  Result := TRSSFeed.Create(Doc) as IRSSBase;
end;



{ TRSSFeed }

constructor TRSSFeed.Create(theDoc: IXMLDOMDocument2);
var
	i : integer;
  channelNodes : IXMLDOMNodeList;
  Node,theNode: IXmlDomNode;
begin
  FDoc:=theDoc;
  theNode:= FDoc.documentElement;
	node := theNode.selectSingleNode('channel');
  fItems := TRSSItems.Create(node);

  FCreator := getNodeVal(node, 'creator');
 	FDescription := getNodeVal(node, 'description');
  FTitle := ExtractNonHTML(getNodeVal(node, 'title'));
  FLink := getNodeVal(node, 'link');
	FVersion := 'RSS ' + getNodeVal(thenode, '@version');

  channelNodes := node.selectNodes('item');
  for i := 0 to channelNodes.Length - 1 do
    	fitems.Add( TRSSItem.Create(channelNodes.item[i]) );
end;

function TRSSFeed.Get_Creator: WideString; begin Result := FCreator; end;
function TRSSFeed.Get_Description: string; begin Result := FDescription; end;
function TRSSFeed.Get_Items: IRSSItemBaseList; begin Result := fItems; end;
function TRSSFeed.Get_Link: WideString; begin Result := FLink; end;
function TRSSFeed.Get_Title: string; begin Result := FTitle; end;
function TRSSFeed.Get_Version: WideString; begin Result := FVersion; end;


{ TRSSItems }

constructor TRSSItems.Create(theNode:IXMLDOMNode);
begin
  fNode:=theNode;
	fItems := THashedStringList.Create;
end;
procedure TRSSItems.Add(item: TInterfacedObject);
begin
	fItems.AddObject((item as TRSSItem).FGuid, item);
end;
function TRSSItems.Get_Count: integer; begin Result := fItems.Count; end;
function TRSSItems.Get_Item(Index: Integer): IRSSItemBase;
begin
	Result := TRSSItem(fItems.Objects[index]);
end;

{ TRSSItem }

constructor TRSSItem.Create(theNode: IXmlDOMNode);
var
	str : WideString;
begin
  FAuthor:='';
  FTitle:='';
  FGuid:='';
  FLink:='';
  FDescription:='';
  FCategory := '';

  if assigned(theNode) then begin
    FNode:=theNode;

    FAuthor := getNodeVal(thenode, 'author');
    if FAuthor = '' then FAuthor := getNodeVal(thenode, 'dc:creator');
    FCategory := getNodeVal(thenode, 'category');
  
    str := getNodeVal(thenode, 'title');
    FTitle := ExtractNonHTML(str);
    FLink := getNodeVal(thenode, 'link');
    FGuid := getNodeVal(thenode, 'guid');
    if FGuid = '' then FGuid := FLink;
    if FGuid = '' then FGuid := FTitle;
    try
      str := getNodeVal(thenode, 'pubDate');
      FPubDate := TW3CDTF.Create(str)
    except
      FPubDate := TW3CDTF.CreateDateTime(0);
    end;

    FDescription := getNodeVal(thenode, 'content');
    if FDescription='' then
      FDescription := getNodeVal(thenode, 'content:encoded');
    if FDescription='' then
      FDescription := getNodeVal(thenode, 'description');
  end
  else
  	FPubDate := TW3CDTF.CreateDatetime(0);
end;

function TRSSItem.Get_Author: string; begin Result := FAuthor; end;
function TRSSItem.Get_Category: string; begin Result := FCategory; end;
function TRSSItem.Get_Creator: WideString; begin Result := Get_Author(); end;
function TRSSItem.Get_Description: string; begin Result := FDescription; end;
function TRSSItem.Get_Guid: WideString; begin Result := FGuid; end;
function TRSSItem.Get_Link: WideString; begin Result := FLink; end;
function TRSSItem.Get_PubDate: TW3CDTF; begin Result := FPubDate; end;
function TRSSItem.Get_Title: string; begin Result := FTitle; end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -