Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 N0body, Feb 3, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator 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

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block