1. Technology

Reading and Manipulating XML files (RSS feeds) with Delphi

By

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://0.tqn.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;
 
  1. About.com
  2. Technology
  3. Delphi
  4. Coding Internet / Network
  5. Reading and Manipulating XML files (RSS feeds) with Delphi

©2014 About.com. All rights reserved.