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

Reading and Manipulating XML files (RSS feeds) with Delphi

By , About.com Guide

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

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  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.