1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Parse An RSS Feed Using Delphi XE5 Firemonkey On Android And IOS

Discussion in 'Delphi Android And IOS' started by AdminDF, Feb 3, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    If you want to manually parse an RSS feed and not use Livebindings here is a code snippet to do that using the built in TXMLDocument. First drop a TXMLDocument on the Form and be sure to set the DOMVendor to ‘ADOM XML v4′ (this will allow it to work on Android and IOS). Next up get your XML string from your REST Client or load it from a file and using XMLDoc.LoadFromXML() to load it into the XML component. Walk through the child nodes until you get to the node depth that you want (in the case of an RSS feed this is three levels deep. Check the NodeName to see if it the one you want (like Title) and then read out the Text value to get the value of that node. If there is a different node name that isn’t in the same you can add code to look for it instead of the sample ones I provided. Check out the full source code snippet below:

    Code Snippet Download


    Code:
    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).NodeName=’channel’) then
    begin
    for II := 0 to IXMLNode(ANode.ChildNodes).ChildNodes.Count – 1 do
    begin
    if(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).NodeName=’item’) then
    begin
    
    for III := 0 to IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes.Count – 1 do
    begin
    if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).NodeName=’title’) then
    begin
    ATitle := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).Text;
    end;
    if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).NodeName=’link’) then
    begin
    ALink := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).Text;
    end;
    if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).NodeName=’description’) then
    begin
    ADesc := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).Text;
    end;
    if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).NodeName=’content:encoded’) then
    begin
    AHTML := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).Text;
    end;
    if(IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).ChildNodes[II]).ChildNodes[III]).NodeName=’pubDate’) then
    begin
    ADate := IXMLNode(IXMLNode(IXMLNode(ANode.ChildNodes).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;
    
     

Share This Page