09-11-2017, Saat: 17:28
(Son Düzenleme: 09-11-2017, Saat: 17:40, Düzenleyen: TescilsizUzman.)
Merhaba,
Web siteleri, site içeriklerini daha fazla hedef kitleye ulaştırmak için çeşitli veri paylaşım yöntemlerini kullanırlar.
Bu yöntemlerin başında JSON ve benzeri API'ler olmak üzere, XML, HTML Table veya RSS yaygın bir şekilde kullanılmaktadır.
@paranoyaq arkadaşımızın sitenin uygulaması konu başlığı altında talep etmiş olduğu; RSS verilerinin okunarak, bir mobil uygulama geliştirilmesi konusunda, kısa bir araştırma yaptım.
Kendisinin paylaşmış olduğu link ve diğer internet ortamındaki kaynaklara baktığımda, parse işlemi ve benzeri birkaç yöntemle RSS çözümü ürettiklerini gördüm.
Oysaki elimizde daha pratik ve güçlü bir Delphi aracı var.
Daha öncede XML Json dosyaları ile Çalışma konu başlığında bahsetmiş olduğum, XML Data Binding Wizard bu iş için biçilmiş kaftandır.
Bildiğiniz gibi RSS verileri de bir nevi XML formatı sunar. Buradan yola çıkarak XML Data Binding Wizard aracı ile @paranoyaq kardeşimizin vermiş olduğu RSS linkini kullanarak, örnek bir uygulama yapalım.
1- Yeni bir Multi-Device Application projesi oluşturalım.
Uygulama tasarımı için;
- Form üzerine 1 adet Toolbar (örnek uygulamada Toolbar yerine TRectangle kullanılmıştır) ve Toolbar üzerine de bir TButton yerleştirelim. Alignment ve benzeri tasarımlarını yapalım.
- XML işlemleri için 1 Adet TXMLDocument, Style işlemleri için de bir TStyleBook kullanalım.
- İşlem durumunu belirtmek için de form üzerine bir adet TAniIndicator yerleştirelim.
- Son olarak RSS verilerini listeleyeceğimiz TListView alarak, forma yerleştirelim ve tasarıma ait diğer özellikleri atayalım (Daha önce bir çok konu başlığında ListView ile ilgili tasarım örneği anlatıldığında bu konu başlığında anlatmayacağım).
2- Yapmış olduğum tasarıma ait ekran görüntüsü aşağıdaki gibidir.
RSS verisini alacağımız Link: http://tekrehberim.com/index.php/feed
Linke baktığımızda XML formatında olduğunu görüyoruz.
3- RSS Linkini ziyaret ederek, içeriğini kopyalayalım ve bir metin belgesi içerisine yapıştıralım. Daha sonra bu dosyayı XML formatında kaydedelim.
Bu işlemden sonra XML Data Binding Wizard aracını kullanabiliriz.
4- File / New / Other menüsünden, Delphi Projects / XML menüsü altında yer alan XML Data Binding'i seçelim ve OK butonuna tıklayalım.
5- Source ekranında, Schema or XML Data File alanında, oluşturduğumuz XML dosyasını seçelim ve Next butonuna tıklayalım.
6- Daha sonra Next butonlarını kullanarak, son aşamada Finish butonu ile XML'e ait sınıfların bulunduğu Unit'in oluşmasını sağlayalım.
Delphi 10.2.1 sürümü ile oluşturulmuş Unit örneği aşağıdadır.
Uygulamanın kodlanması;
Private bölümünde, RSS linkimizi sabit olarak tanımlayalım.
7- RSS verilerini, almak için Butonun OnClick olayına aşağıdaki kodları ekleyelim.
RSS Uygulamamızın ekran görüntüsü aşağıdaki gibidir.
Faydalı olması dileğiyle...
Test amaçlı uygulama geliştirmek isteyenler için başka bir (DelphiCan'ın) RSS Linki: http://www.delphican.com/syndication.php...0&limit=15
Web siteleri, site içeriklerini daha fazla hedef kitleye ulaştırmak için çeşitli veri paylaşım yöntemlerini kullanırlar.
Bu yöntemlerin başında JSON ve benzeri API'ler olmak üzere, XML, HTML Table veya RSS yaygın bir şekilde kullanılmaktadır.
@paranoyaq arkadaşımızın sitenin uygulaması konu başlığı altında talep etmiş olduğu; RSS verilerinin okunarak, bir mobil uygulama geliştirilmesi konusunda, kısa bir araştırma yaptım.
Kendisinin paylaşmış olduğu link ve diğer internet ortamındaki kaynaklara baktığımda, parse işlemi ve benzeri birkaç yöntemle RSS çözümü ürettiklerini gördüm.
Oysaki elimizde daha pratik ve güçlü bir Delphi aracı var.
Daha öncede XML Json dosyaları ile Çalışma konu başlığında bahsetmiş olduğum, XML Data Binding Wizard bu iş için biçilmiş kaftandır.
Bildiğiniz gibi RSS verileri de bir nevi XML formatı sunar. Buradan yola çıkarak XML Data Binding Wizard aracı ile @paranoyaq kardeşimizin vermiş olduğu RSS linkini kullanarak, örnek bir uygulama yapalım.
1- Yeni bir Multi-Device Application projesi oluşturalım.
Uygulama tasarımı için;
- Form üzerine 1 adet Toolbar (örnek uygulamada Toolbar yerine TRectangle kullanılmıştır) ve Toolbar üzerine de bir TButton yerleştirelim. Alignment ve benzeri tasarımlarını yapalım.
- XML işlemleri için 1 Adet TXMLDocument, Style işlemleri için de bir TStyleBook kullanalım.
- İşlem durumunu belirtmek için de form üzerine bir adet TAniIndicator yerleştirelim.
- Son olarak RSS verilerini listeleyeceğimiz TListView alarak, forma yerleştirelim ve tasarıma ait diğer özellikleri atayalım (Daha önce bir çok konu başlığında ListView ile ilgili tasarım örneği anlatıldığında bu konu başlığında anlatmayacağım).
2- Yapmış olduğum tasarıma ait ekran görüntüsü aşağıdaki gibidir.
RSS verisini alacağımız Link: http://tekrehberim.com/index.php/feed
Linke baktığımızda XML formatında olduğunu görüyoruz.
3- RSS Linkini ziyaret ederek, içeriğini kopyalayalım ve bir metin belgesi içerisine yapıştıralım. Daha sonra bu dosyayı XML formatında kaydedelim.
Bu işlemden sonra XML Data Binding Wizard aracını kullanabiliriz.
4- File / New / Other menüsünden, Delphi Projects / XML menüsü altında yer alan XML Data Binding'i seçelim ve OK butonuna tıklayalım.
5- Source ekranında, Schema or XML Data File alanında, oluşturduğumuz XML dosyasını seçelim ve Next butonuna tıklayalım.
6- Daha sonra Next butonlarını kullanarak, son aşamada Finish butonu ile XML'e ait sınıfların bulunduğu Unit'in oluşmasını sağlayalım.
Delphi 10.2.1 sürümü ile oluşturulmuş Unit örneği aşağıdadır.
{*******************************************************} { } { XML Data Binding } { } { Generated on: 9.11.2017 14:21:57 } { Generated from: C:\Users\User\Desktop\new.xml } { Settings stored in: C:\Users\User\Desktop\new.xdb } { } {*******************************************************} unit tekrehberimXMLRSS; interface uses xmldom, XMLDoc, XMLIntf; type { Forward Decls } IXMLRssType = interface; IXMLChannelType = interface; IXMLLinkType = interface; IXMLLinkTypeList = interface; IXMLImageType = interface; IXMLItemType = interface; IXMLItemTypeList = interface; IXMLGuidType = interface; IXMLString_List = interface; { IXMLRssType } IXMLRssType = interface(IXMLNode) ['{5352C507-61EC-4DE5-9300-46FD170C48B6}'] { Property Accessors } function Get_Version: UnicodeString; function Get_Channel: IXMLChannelType; procedure Set_Version(Value: UnicodeString); { Methods & Properties } property Version: UnicodeString read Get_Version write Set_Version; property Channel: IXMLChannelType read Get_Channel; end; { IXMLChannelType } IXMLChannelType = interface(IXMLNode) ['{2F44D6CC-33ED-433E-B5FE-646ABAFDE730}'] { Property Accessors } function Get_Title: UnicodeString; function Get_Link: IXMLLinkTypeList; function Get_Description: UnicodeString; function Get_LastBuildDate: UnicodeString; function Get_Language: UnicodeString; function Get_UpdatePeriod: UnicodeString; function Get_UpdateFrequency: Integer; function Get_Generator: UnicodeString; function Get_Image: IXMLImageType; function Get_Item: IXMLItemTypeList; procedure Set_Title(Value: UnicodeString); procedure Set_Description(Value: UnicodeString); procedure Set_LastBuildDate(Value: UnicodeString); procedure Set_Language(Value: UnicodeString); procedure Set_UpdatePeriod(Value: UnicodeString); procedure Set_UpdateFrequency(Value: Integer); procedure Set_Generator(Value: UnicodeString); { Methods & Properties } property Title: UnicodeString read Get_Title write Set_Title; property Link: IXMLLinkTypeList read Get_Link; property Description: UnicodeString read Get_Description write Set_Description; property LastBuildDate: UnicodeString read Get_LastBuildDate write Set_LastBuildDate; property Language: UnicodeString read Get_Language write Set_Language; property UpdatePeriod: UnicodeString read Get_UpdatePeriod write Set_UpdatePeriod; property UpdateFrequency: Integer read Get_UpdateFrequency write Set_UpdateFrequency; property Generator: UnicodeString read Get_Generator write Set_Generator; property Image: IXMLImageType read Get_Image; property Item: IXMLItemTypeList read Get_Item; end; { IXMLLinkType } IXMLLinkType = interface(IXMLNode) ['{9F072DC3-4A33-49B0-9F3B-3729883F97B7}'] { Property Accessors } function Get_Href: UnicodeString; function Get_Rel: UnicodeString; function Get_Type_: UnicodeString; procedure Set_Href(Value: UnicodeString); procedure Set_Rel(Value: UnicodeString); procedure Set_Type_(Value: UnicodeString); { Methods & Properties } property Href: UnicodeString read Get_Href write Set_Href; property Rel: UnicodeString read Get_Rel write Set_Rel; property Type_: UnicodeString read Get_Type_ write Set_Type_; end; { IXMLLinkTypeList } IXMLLinkTypeList = interface(IXMLNodeCollection) ['{A9ECE121-0B4C-45FE-AFE0-091BCFCB99A2}'] { Methods & Properties } function Add: IXMLLinkType; function Insert(const Index: Integer): IXMLLinkType; function Get_Item(Index: Integer): IXMLLinkType; property Items[Index: Integer]: IXMLLinkType read Get_Item; default; end; { IXMLImageType } IXMLImageType = interface(IXMLNode) ['{4F91CFEF-9519-40AE-8425-C9A50830B150}'] { Property Accessors } function Get_Url: UnicodeString; function Get_Title: UnicodeString; function Get_Link: UnicodeString; function Get_Width: Integer; function Get_Height: Integer; procedure Set_Url(Value: UnicodeString); procedure Set_Title(Value: UnicodeString); procedure Set_Link(Value: UnicodeString); procedure Set_Width(Value: Integer); procedure Set_Height(Value: Integer); { Methods & Properties } property Url: UnicodeString read Get_Url write Set_Url; property Title: UnicodeString read Get_Title write Set_Title; property Link: UnicodeString read Get_Link write Set_Link; property Width: Integer read Get_Width write Set_Width; property Height: Integer read Get_Height write Set_Height; end; { IXMLItemType } IXMLItemType = interface(IXMLNode) ['{843306D1-6CCC-467F-BF49-3AA698FE9380}'] { Property Accessors } function Get_Title: UnicodeString; function Get_Link: UnicodeString; function Get_Comments: IXMLString_List; function Get_PubDate: UnicodeString; function Get_Creator: UnicodeString; function Get_Category: IXMLString_List; function Get_Guid: IXMLGuidType; function Get_Description: UnicodeString; function Get_Encoded: UnicodeString; function Get_CommentRss: UnicodeString; procedure Set_Title(Value: UnicodeString); procedure Set_Link(Value: UnicodeString); procedure Set_PubDate(Value: UnicodeString); procedure Set_Creator(Value: UnicodeString); procedure Set_Description(Value: UnicodeString); procedure Set_Encoded(Value: UnicodeString); procedure Set_CommentRss(Value: UnicodeString); { Methods & Properties } property Title: UnicodeString read Get_Title write Set_Title; property Link: UnicodeString read Get_Link write Set_Link; property Comments: IXMLString_List read Get_Comments; property PubDate: UnicodeString read Get_PubDate write Set_PubDate; property Creator: UnicodeString read Get_Creator write Set_Creator; property Category: IXMLString_List read Get_Category; property Guid: IXMLGuidType read Get_Guid; property Description: UnicodeString read Get_Description write Set_Description; property Encoded: UnicodeString read Get_Encoded write Set_Encoded; property CommentRss: UnicodeString read Get_CommentRss write Set_CommentRss; end; { IXMLItemTypeList } IXMLItemTypeList = interface(IXMLNodeCollection) ['{15D9654D-1B11-4308-8A60-BC362E7174EE}'] { Methods & Properties } function Add: IXMLItemType; function Insert(const Index: Integer): IXMLItemType; function Get_Item(Index: Integer): IXMLItemType; property Items[Index: Integer]: IXMLItemType read Get_Item; default; end; { IXMLGuidType } IXMLGuidType = interface(IXMLNode) ['{0D014BD3-91D1-4BEB-906A-DBFB0DA9FA41}'] { Property Accessors } function Get_IsPermaLink: UnicodeString; procedure Set_IsPermaLink(Value: UnicodeString); { Methods & Properties } property IsPermaLink: UnicodeString read Get_IsPermaLink write Set_IsPermaLink; end; { IXMLString_List } IXMLString_List = interface(IXMLNodeCollection) ['{30048FF8-F8E0-436A-9F7C-E88F5B35E10C}'] { Methods & Properties } function Add(const Value: UnicodeString): IXMLNode; function Insert(const Index: Integer; const Value: UnicodeString): IXMLNode; function Get_Item(Index: Integer): UnicodeString; property Items[Index: Integer]: UnicodeString read Get_Item; default; end; { Forward Decls } TXMLRssType = class; TXMLChannelType = class; TXMLLinkType = class; TXMLLinkTypeList = class; TXMLImageType = class; TXMLItemType = class; TXMLItemTypeList = class; TXMLGuidType = class; TXMLString_List = class; { TXMLRssType } TXMLRssType = class(TXMLNode, IXMLRssType) protected { IXMLRssType } function Get_Version: UnicodeString; function Get_Channel: IXMLChannelType; procedure Set_Version(Value: UnicodeString); public procedure AfterConstruction; override; end; { TXMLChannelType } TXMLChannelType = class(TXMLNode, IXMLChannelType) private FLink: IXMLLinkTypeList; FItem: IXMLItemTypeList; protected { IXMLChannelType } function Get_Title: UnicodeString; function Get_Link: IXMLLinkTypeList; function Get_Description: UnicodeString; function Get_LastBuildDate: UnicodeString; function Get_Language: UnicodeString; function Get_UpdatePeriod: UnicodeString; function Get_UpdateFrequency: Integer; function Get_Generator: UnicodeString; function Get_Image: IXMLImageType; function Get_Item: IXMLItemTypeList; procedure Set_Title(Value: UnicodeString); procedure Set_Description(Value: UnicodeString); procedure Set_LastBuildDate(Value: UnicodeString); procedure Set_Language(Value: UnicodeString); procedure Set_UpdatePeriod(Value: UnicodeString); procedure Set_UpdateFrequency(Value: Integer); procedure Set_Generator(Value: UnicodeString); public procedure AfterConstruction; override; end; { TXMLLinkType } TXMLLinkType = class(TXMLNode, IXMLLinkType) protected { IXMLLinkType } function Get_Href: UnicodeString; function Get_Rel: UnicodeString; function Get_Type_: UnicodeString; procedure Set_Href(Value: UnicodeString); procedure Set_Rel(Value: UnicodeString); procedure Set_Type_(Value: UnicodeString); end; { TXMLLinkTypeList } TXMLLinkTypeList = class(TXMLNodeCollection, IXMLLinkTypeList) protected { IXMLLinkTypeList } function Add: IXMLLinkType; function Insert(const Index: Integer): IXMLLinkType; function Get_Item(Index: Integer): IXMLLinkType; end; { TXMLImageType } TXMLImageType = class(TXMLNode, IXMLImageType) protected { IXMLImageType } function Get_Url: UnicodeString; function Get_Title: UnicodeString; function Get_Link: UnicodeString; function Get_Width: Integer; function Get_Height: Integer; procedure Set_Url(Value: UnicodeString); procedure Set_Title(Value: UnicodeString); procedure Set_Link(Value: UnicodeString); procedure Set_Width(Value: Integer); procedure Set_Height(Value: Integer); end; { TXMLItemType } TXMLItemType = class(TXMLNode, IXMLItemType) private FComments: IXMLString_List; FCategory: IXMLString_List; protected { IXMLItemType } function Get_Title: UnicodeString; function Get_Link: UnicodeString; function Get_Comments: IXMLString_List; function Get_PubDate: UnicodeString; function Get_Creator: UnicodeString; function Get_Category: IXMLString_List; function Get_Guid: IXMLGuidType; function Get_Description: UnicodeString; function Get_Encoded: UnicodeString; function Get_CommentRss: UnicodeString; procedure Set_Title(Value: UnicodeString); procedure Set_Link(Value: UnicodeString); procedure Set_PubDate(Value: UnicodeString); procedure Set_Creator(Value: UnicodeString); procedure Set_Description(Value: UnicodeString); procedure Set_Encoded(Value: UnicodeString); procedure Set_CommentRss(Value: UnicodeString); public procedure AfterConstruction; override; end; { TXMLItemTypeList } TXMLItemTypeList = class(TXMLNodeCollection, IXMLItemTypeList) protected { IXMLItemTypeList } function Add: IXMLItemType; function Insert(const Index: Integer): IXMLItemType; function Get_Item(Index: Integer): IXMLItemType; end; { TXMLGuidType } TXMLGuidType = class(TXMLNode, IXMLGuidType) protected { IXMLGuidType } function Get_IsPermaLink: UnicodeString; procedure Set_IsPermaLink(Value: UnicodeString); end; { TXMLString_List } TXMLString_List = class(TXMLNodeCollection, IXMLString_List) protected { IXMLString_List } function Add(const Value: UnicodeString): IXMLNode; function Insert(const Index: Integer; const Value: UnicodeString): IXMLNode; function Get_Item(Index: Integer): UnicodeString; end; { Global Functions } function Getrss(Doc: IXMLDocument): IXMLRssType; function Loadrss(const FileName: string): IXMLRssType; function Newrss: IXMLRssType; const TargetNamespace = ''; implementation { Global Functions } function Getrss(Doc: IXMLDocument): IXMLRssType; begin Result := Doc.GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType; end; function Loadrss(const FileName: string): IXMLRssType; begin Result := LoadXMLDocument(FileName).GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType; end; function Newrss: IXMLRssType; begin Result := NewXMLDocument.GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType; end; { TXMLRssType } procedure TXMLRssType.AfterConstruction; begin RegisterChildNode('channel', TXMLChannelType); inherited; end; function TXMLRssType.Get_Version: UnicodeString; begin Result := AttributeNodes['version'].Text; end; procedure TXMLRssType.Set_Version(Value: UnicodeString); begin SetAttribute('version', Value); end; function TXMLRssType.Get_Channel: IXMLChannelType; begin Result := ChildNodes['channel'] as IXMLChannelType; end; { TXMLChannelType } procedure TXMLChannelType.AfterConstruction; begin RegisterChildNode('link', TXMLLinkType); RegisterChildNode('image', TXMLImageType); RegisterChildNode('item', TXMLItemType); FLink := CreateCollection(TXMLLinkTypeList, IXMLLinkType, 'link') as IXMLLinkTypeList; FItem := CreateCollection(TXMLItemTypeList, IXMLItemType, 'item') as IXMLItemTypeList; inherited; end; function TXMLChannelType.Get_Title: UnicodeString; begin Result := ChildNodes['title'].Text; end; procedure TXMLChannelType.Set_Title(Value: UnicodeString); begin ChildNodes['title'].NodeValue := Value; end; function TXMLChannelType.Get_Link: IXMLLinkTypeList; begin Result := FLink; end; function TXMLChannelType.Get_Description: UnicodeString; begin Result := ChildNodes['description'].Text; end; procedure TXMLChannelType.Set_Description(Value: UnicodeString); begin ChildNodes['description'].NodeValue := Value; end; function TXMLChannelType.Get_LastBuildDate: UnicodeString; begin Result := ChildNodes['lastBuildDate'].Text; end; procedure TXMLChannelType.Set_LastBuildDate(Value: UnicodeString); begin ChildNodes['lastBuildDate'].NodeValue := Value; end; function TXMLChannelType.Get_Language: UnicodeString; begin Result := ChildNodes['language'].Text; end; procedure TXMLChannelType.Set_Language(Value: UnicodeString); begin ChildNodes['language'].NodeValue := Value; end; function TXMLChannelType.Get_UpdatePeriod: UnicodeString; begin Result := ChildNodes['updatePeriod'].Text; end; procedure TXMLChannelType.Set_UpdatePeriod(Value: UnicodeString); begin ChildNodes['updatePeriod'].NodeValue := Value; end; function TXMLChannelType.Get_UpdateFrequency: Integer; begin Result := ChildNodes['updateFrequency'].NodeValue; end; procedure TXMLChannelType.Set_UpdateFrequency(Value: Integer); begin ChildNodes['updateFrequency'].NodeValue := Value; end; function TXMLChannelType.Get_Generator: UnicodeString; begin Result := ChildNodes['generator'].Text; end; procedure TXMLChannelType.Set_Generator(Value: UnicodeString); begin ChildNodes['generator'].NodeValue := Value; end; function TXMLChannelType.Get_Image: IXMLImageType; begin Result := ChildNodes['image'] as IXMLImageType; end; function TXMLChannelType.Get_Item: IXMLItemTypeList; begin Result := FItem; end; { TXMLLinkType } function TXMLLinkType.Get_Href: UnicodeString; begin Result := AttributeNodes['href'].Text; end; procedure TXMLLinkType.Set_Href(Value: UnicodeString); begin SetAttribute('href', Value); end; function TXMLLinkType.Get_Rel: UnicodeString; begin Result := AttributeNodes['rel'].Text; end; procedure TXMLLinkType.Set_Rel(Value: UnicodeString); begin SetAttribute('rel', Value); end; function TXMLLinkType.Get_Type_: UnicodeString; begin Result := AttributeNodes['type'].Text; end; procedure TXMLLinkType.Set_Type_(Value: UnicodeString); begin SetAttribute('type', Value); end; { TXMLLinkTypeList } function TXMLLinkTypeList.Add: IXMLLinkType; begin Result := AddItem(-1) as IXMLLinkType; end; function TXMLLinkTypeList.Insert(const Index: Integer): IXMLLinkType; begin Result := AddItem(Index) as IXMLLinkType; end; function TXMLLinkTypeList.Get_Item(Index: Integer): IXMLLinkType; begin Result := List[Index] as IXMLLinkType; end; { TXMLImageType } function TXMLImageType.Get_Url: UnicodeString; begin Result := ChildNodes['url'].Text; end; procedure TXMLImageType.Set_Url(Value: UnicodeString); begin ChildNodes['url'].NodeValue := Value; end; function TXMLImageType.Get_Title: UnicodeString; begin Result := ChildNodes['title'].Text; end; procedure TXMLImageType.Set_Title(Value: UnicodeString); begin ChildNodes['title'].NodeValue := Value; end; function TXMLImageType.Get_Link: UnicodeString; begin Result := ChildNodes['link'].Text; end; procedure TXMLImageType.Set_Link(Value: UnicodeString); begin ChildNodes['link'].NodeValue := Value; end; function TXMLImageType.Get_Width: Integer; begin Result := ChildNodes['width'].NodeValue; end; procedure TXMLImageType.Set_Width(Value: Integer); begin ChildNodes['width'].NodeValue := Value; end; function TXMLImageType.Get_Height: Integer; begin Result := ChildNodes['height'].NodeValue; end; procedure TXMLImageType.Set_Height(Value: Integer); begin ChildNodes['height'].NodeValue := Value; end; { TXMLItemType } procedure TXMLItemType.AfterConstruction; begin RegisterChildNode('guid', TXMLGuidType); FComments := CreateCollection(TXMLString_List, IXMLNode, 'comments') as IXMLString_List; FCategory := CreateCollection(TXMLString_List, IXMLNode, 'category') as IXMLString_List; inherited; end; function TXMLItemType.Get_Title: UnicodeString; begin Result := ChildNodes['title'].Text; end; procedure TXMLItemType.Set_Title(Value: UnicodeString); begin ChildNodes['title'].NodeValue := Value; end; function TXMLItemType.Get_Link: UnicodeString; begin Result := ChildNodes['link'].Text; end; procedure TXMLItemType.Set_Link(Value: UnicodeString); begin ChildNodes['link'].NodeValue := Value; end; function TXMLItemType.Get_Comments: IXMLString_List; begin Result := FComments; end; function TXMLItemType.Get_PubDate: UnicodeString; begin Result := ChildNodes['pubDate'].Text; end; procedure TXMLItemType.Set_PubDate(Value: UnicodeString); begin ChildNodes['pubDate'].NodeValue := Value; end; function TXMLItemType.Get_Creator: UnicodeString; begin Result := ChildNodes['creator'].Text; end; procedure TXMLItemType.Set_Creator(Value: UnicodeString); begin ChildNodes['creator'].NodeValue := Value; end; function TXMLItemType.Get_Category: IXMLString_List; begin Result := FCategory; end; function TXMLItemType.Get_Guid: IXMLGuidType; begin Result := ChildNodes['guid'] as IXMLGuidType; end; function TXMLItemType.Get_Description: UnicodeString; begin Result := ChildNodes['description'].Text; end; procedure TXMLItemType.Set_Description(Value: UnicodeString); begin ChildNodes['description'].NodeValue := Value; end; function TXMLItemType.Get_Encoded: UnicodeString; begin Result := ChildNodes['encoded'].Text; end; procedure TXMLItemType.Set_Encoded(Value: UnicodeString); begin ChildNodes['encoded'].NodeValue := Value; end; function TXMLItemType.Get_CommentRss: UnicodeString; begin Result := ChildNodes['commentRss'].Text; end; procedure TXMLItemType.Set_CommentRss(Value: UnicodeString); begin ChildNodes['commentRss'].NodeValue := Value; end; { TXMLItemTypeList } function TXMLItemTypeList.Add: IXMLItemType; begin Result := AddItem(-1) as IXMLItemType; end; function TXMLItemTypeList.Insert(const Index: Integer): IXMLItemType; begin Result := AddItem(Index) as IXMLItemType; end; function TXMLItemTypeList.Get_Item(Index: Integer): IXMLItemType; begin Result := List[Index] as IXMLItemType; end; { TXMLGuidType } function TXMLGuidType.Get_IsPermaLink: UnicodeString; begin Result := AttributeNodes['isPermaLink'].Text; end; procedure TXMLGuidType.Set_IsPermaLink(Value: UnicodeString); begin SetAttribute('isPermaLink', Value); end; { TXMLString_List } function TXMLString_List.Add(const Value: UnicodeString): IXMLNode; begin Result := AddItem(-1); Result.NodeValue := Value; end; function TXMLString_List.Insert(const Index: Integer; const Value: UnicodeString): IXMLNode; begin Result := AddItem(Index); Result.NodeValue := Value; end; function TXMLString_List.Get_Item(Index: Integer): UnicodeString; begin Result := List[Index].NodeValue; end; end.
Uygulamanın kodlanması;
Private bölümünde, RSS linkimizi sabit olarak tanımlayalım.
private Const urlRSS: String = 'http://www.tekrehberim.com/index.php/feed/';
7- RSS verilerini, almak için Butonun OnClick olayına aşağıdaki kodları ekleyelim.
var RssXml: String; begin ListView1.Items.Clear; AniIndicator1.Enabled := True; AniIndicator1.Visible := True; TThread.CreateAnonymousThread( procedure() var IdHTTP1: TIdHTTP; cnlHaber, Eleman: IXMLNode; begin IdHTTP1 := TIdHTTP.Create(nil); ListView1.BeginUpdate; try RssXml := IdHTTP1.Get(urlRSS); XMLDocument1.LoadFromXML(RssXml); cnlHaber := XMLDocument1.DocumentElement.ChildNodes.FindNode('channel'); TThread.Synchronize(TThread.CurrentThread, procedure var i: integer; LItem: TListViewItem; begin for i := 0 to cnlHaber.ChildNodes.Count - 1 do begin Eleman := cnlHaber.ChildNodes[I]; if Eleman.NodeName = 'item' then begin LItem := ListView1.Items.Add; LItem.Data['itmBaslik'] := VarToStr(Eleman.ChildValues['title']); LItem.Data['itmTarih'] := VarToStr(Eleman.ChildValues['pubDate']); LItem.Data['itmKategori'] := VarToStr(Eleman.ChildValues['category']); LItem.Data['itmIcerik'] := VarToStr(Eleman.ChildValues['description']); LItem.Data['itmURL'] := 'Link: ' + VarToStr(Eleman.ChildValues['link']); end; end end); finally IdHTTP1.DisposeOf; ListView1.EndUpdate; AniIndicator1.Enabled := False; AniIndicator1.Visible := False; end; end).Start; end;
RSS Uygulamamızın ekran görüntüsü aşağıdaki gibidir.
Faydalı olması dileğiyle...
Test amaçlı uygulama geliştirmek isteyenler için başka bir (DelphiCan'ın) RSS Linki: http://www.delphican.com/syndication.php...0&limit=15