Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Reading and Manipulating XML files (RSS feeds) with Delphi

By Zarko Gajic, About.com

3 of 4

Parsing XML, Delphi way

Create a new Delphi project and drop a TListView (Name: 'LV') component on a form. Add a TButton (Name : 'btnRefresh') and a TXMLDocument (Name : 'XMLDoc'). Next, add three columns to the ListView component (Title, Link and Description). Finally, add the code to download the XML file, parse it with TXMLDocument and display inside the ListView in the button's OnClick event handler.

Below you can find the portion of that code. The entire code is available for download.

var
   StartItemNode : IXMLNode;
   ANode : IXMLNode;
   STitle, sDesc, sLink : WideString;
begin
...
  //points to local XML file in "original" code
  XMLDoc.FileName := 'http://z.about.com/6/g/delphi/b/index.xml';
  XMLDoc.Active:=True;

  StartItemNode := XMLDoc.DocumentElement.ChildNodes.First.ChildNodes.FindNode('item') ;

  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;

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Internet / Network
  5. Reading and Manipulating XML files (RSS feeds) with Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.