Home arrow Delphi-Kylix arrow Page 2 - Finishing an RSS Reader
DELPHI-KYLIX

Finishing an RSS Reader


In this part of the article, we will discuss how to get an RSS file from a website, and store it on the local disk for easy viewing. This way we do not need to be connected to the Internet.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
August 23, 2006
TABLE OF CONTENTS:
  1. · Finishing an RSS Reader
  2. · New code
  3. · Getting files from a website
  4. · Full code for the RSS reader

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Finishing an RSS Reader - New code
(Page 2 of 4 )

Now that we've done the set up, let's get on with the code. First, let's add new code to the OnCreate event. Go to the object inspectors' event tab and double click on the OnCreate event. Add the following code before the last "end;" of the procedure :

Var
rec:TSearchRec;
....
if not DirectoryExists('MyFeeds') then createdir('MyFeeds');
// find all files matching *.xml in the current dir
if FindFirst('MyFeeds*.xml', faAnyFile, rec) = 0 then
begin
with tv.Items.AddFirst(nil,  'MyFeeds') do
begin
Selected:=true;
end;
repeat
with tv.Items.AddChildFirst(  tv.Selected,  rec.Name) do
begin
MakeVisible;
end;
until FindNext(rec) <> 0;
// Must free up resources used by these successful finds
FindClose(rec);
end
else begin
with tv.Items.AddFirst(  nil,  'No Files Found'  ) do
begin
Selected := true;
end;
end;

This piece of code searches for all the files with a  ".xml" extension and then adds them to the treeview.

Next, we need to open up the XML file when the user clicks on a filename from the XML treeview, so select the treeview component and go to the object inspectors' events tab. Double click on the  DblClick event and add the following code:

procedure TForm1.tvxmlDblClick(Sender: TObject);
var
StartItemNode : IXMLNode;
ANode : IXMLNode;
STitle, sDesc, sLink : WideString;
begin
LV.Clear;
if (tvxml.Selected.Level <> 0) then begin
fn:=tv.Selected.Text;
form1.Caption:='';
form1.Caption:='RSS XML File Reader - '+fn;  
//if not DirectoryExists('MyFeeds') then CreateDir('MyFeeds');
//points to local XML file in "original" code
XMLDoc.FileName :='MyFeeds'+fn;
XMLDoc.Active:=True;
StartItemNode := XMLDoc.DocumentElement.ChildNodes.First.ChildNodes.FindNode('item') ;
if StartItemNode = nil then begin
showmessage('Error');
exit;
end;
ANode := StartItemNode;
repeat
STitle := ANode.ChildNodes['title'].Text;
sLink := ANode.ChildNodes['link'].Text;
sDesc := ANode.ChildNodes['description'].Text;
//add to list view
with LV.Items.Add do
begin
Caption := STitle;
SubItems.Add(sLink) ;
SubItems.Add(sDesc)
end;
ANode := ANode.NextSibling;
until ANode = nil;
end;
end;

As you've probably worked out by now, the code parses the contents of the XML file onto the listview component, based on the Title, Link and Description tags. Have a look at the parser in action below:


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials