procedure TMainForm.RESTRequestAfterExecute(Sender: TCustomRESTRequest);
var
ANode: IXmlNode;
AList, AList2: TList;
I, II, III: Integer;
ATitle, ALink, AType, ADate, ADesc, AImage, AHTML: String;
begin
if (RESTResponse.Content<>'') AND (FLoadOnce=False) then
begin
FLoadOnce := True;
XMLDoc.LoadFromXML(RESTResponse.Content);
XMLDoc.Active := True;
ANode := FXMLDoc.ChildNodes.FindNode('rss');
for I := 0 to ANode.ChildNodes.Count - 1 do
begin
if (IXMLNode(ANode.ChildNodes[I]).NodeName='channel') then
begin
for II := 0 to IXMLNode(ANode.ChildNodes[I]).ChildNodes.Count - 1 do
begin
if(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).NodeName='item') then
begin
for III := 0 to IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes.Count - 1 do
begin
if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).NodeName='title') then
begin
ATitle := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).Text;
end;
if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).NodeName='link') then
begin
ALink := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).Text;
end;
if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).NodeName='description') then
begin
ADesc := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).Text;
end;
if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).NodeName='content:encoded') then
begin
AHTML := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).Text;
end;
if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).NodeName='pubDate') then
begin
ADate := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes[I]).ChildNodes[II]).ChildNodes[III]).Text;
end;
end;
// parse an image out of the description
AImage := Copy(ADesc,Pos('src="',ADesc)+5,Pos('"',ADesc)+5));
// do something with your feed data like add it to a TListBox
AddRSSItem(ATitle, ALink, ADesc, AImage, ADate);
Application.ProcessMessages;
end;
end;
end;
end;
end;
end;
This code snippet is in the the AfterExecute event of a TRESTRequest component and reads out the XML from the Content property. Download a copy of the sample code snippet.