RSS parsing help (simple)

Discussion in 'iOS Programming' started by johnnyfla123, Nov 19, 2013.

  1. johnnyfla123 macrumors newbie

    Joined:
    Jun 15, 2013
    #1
    So i am working on a rss feed parser for a clients wordpress.

    I am making the description in the tableview that selects the articles that are pulled from the feed. This is the description being called upon.

    Code:
        NSString* description = [NSString stringWithFormat:@"%@...",   [self.description substringToIndex:100]];
        description = [description gtm_stringBySanitizingAndEscapingForXML];
        description = [description gtm_stringByUnescapingFromHTML];
    
    Code:
        description = [description gtm_stringBySanitizingAndEscapingForXML];
    
    Takes out the html that is pulled from the feed.

    and
    Code:
        description = [description gtm_stringByUnescapingFromHTML];
    
    Corrects grammar.


    Both of the api's can be found here:
    https://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/

    GTMNSString+XML
    GTMNSString+HTML



    Both work by them selves but i need the data to go through both of them to get the final product i dont know how i am supposed to write that new line
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    They already are. By assigning the return values to description, you have changed description (which actually just changes the pointer). What leads you to believe your code doesn't work correctly? Do you have some debugging output you wish to share?
     
  3. johnnyfla123 thread starter macrumors newbie

    Joined:
    Jun 15, 2013
    #3
    it works if i use each individually like:

    Code:
        NSString *description = [NSString stringWithFormat:@"%@...", [self.description substringToIndex:100]];
        description = [description gtm_stringBySanitizingAndEscapingForXML];
    
    or

    Code:
        NSString *description = [NSString stringWithFormat:@"%@...", [self.description substringToIndex:100]];
        description = [description gtm_stringByUnescapingFromHTML];
    


    i need it to be gtm_stringByUnescapingFromHTML + gtm_stringBySanitizingAndEscapingForXML


    by them selves each does the job. i don't know how to edit

    Code:
    description = [description gtm_stringByUnescapingFromHTML];
    
    to have both the xml and html
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Can you post some examples of what you're trying to parse and what each of those calls does to it and what you would like the final result to be?
     
  5. johnnyfla123 thread starter macrumors newbie

    Joined:
    Jun 15, 2013
    #5

    Heres the github of an example:

    https://github.com/icanzilb/Advanced-RSS-reader


    page 2 of: http://www.touch-code-magazine.com/tutorial-building-advanced-rss-reader-with-ios6/2/

    will give you more info in the HTML one. This app has the HTML one added. I added the XML one to the app. I want ot to use both the html and the xml. I provided the exact line that needs to be changed and the values form the html and xml api i need
     
  6. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #6
    if you are simply trying to get it all into one like you could put

    Code:
    
    description = [[description gtm_stringBySanitizingAndEscapingForXML] gtm_stringByUnescapingFromHTML];
    
    
    but what dejo is trying to say is that this would work too

    Code:
    //at the start it is normal description
    
    description = [description gtm_stringBySanitizingAndEscapingForXML];
    //at this point description is sanitized and escaped for XML
    
    description = [description gtm_stringByUnescapingFromHTML];
    //now it is also unescaped from HTML
    
     
  7. johnnyfla123, Nov 20, 2013
    Last edited by a moderator: Nov 20, 2013

    johnnyfla123 thread starter macrumors newbie

    Joined:
    Jun 15, 2013
    #7
    Yeah i tried but i think im just missing part that you need to understand it still.

    heres the .m that handles the amending:

    Code:
    //
    //  RSSItem.m
    //  ARSSReader
    //
    //  Created by Marin Todorov on 29/10/2012.
    //  Copyright (c) 2012 Underplot ltd. All rights reserved.
    //
    
    #import "RSSItem.h"
    #import "GTMNSString+HTML.h"
    #import "GTMNSString+XML.h"
    
    @implementation RSSItem
    
    -(NSAttributedString*)cellMessage
    {
        if (_cellMessage!=nil) return _cellMessage;
        
        NSDictionary* boldStyle = @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica-Bold" size:16.0]};
        NSDictionary* normalStyle = @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:16.0]};
        
        NSMutableAttributedString* articleAbstract = [[NSMutableAttributedString alloc] initWithString:self.title];
        
        [articleAbstract setAttributes:boldStyle
                                 range:NSMakeRange(0, self.title.length)];
        
        [articleAbstract appendAttributedString:
         [[NSAttributedString alloc] initWithString:@"\n\n"]
         ];
        
        int startIndex = [articleAbstract length];
        
        NSString *description = [NSString stringWithFormat:@"%@...", [self.description substringToIndex:100]];
        //description = [description gtm_stringBySanitizingAndEscapingForXML];
        //description = [description gtm_stringByUnescapingFromHTML];
        description = [[description gtm_stringBySanitizingAndEscapingForXML] gtm_stringByUnescapingFromHTML];
        
        [articleAbstract appendAttributedString:
        [[NSAttributedString alloc] initWithString: description]
         ];
        
        [articleAbstract setAttributes:normalStyle
                                 range:NSMakeRange(startIndex, articleAbstract.length - startIndex)];
        
        _cellMessage = articleAbstract;
        return _cellMessage;
        
    }
    
    @end
    
    
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    As I asked for earlier, if you could provide some examples, that might help us to better understand what it is you're trying to achieve.
     
  9. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #9
    To clarify, I assume you're asking for example data, not code. That is, the input data (strings) being used at each of the gtm_XXX method invocations.
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    That is correct, good sir!
     
  11. johnnyfla123 thread starter macrumors newbie

    Joined:
    Jun 15, 2013
    #11
    so i tried this:

    Code:
      NSString* description1 = [NSString stringWithFormat:@"%@...", [self.description substringToIndex:100]];
        description1 = [description1 gtm_stringBySanitizingAndEscapingForXML];
        
        
        NSString* description2 = [NSString stringWithFormat:@"%@...", [self.description substringToIndex:100]];
        description2 = [description2 gtm_stringByUnescapingFromHTML];
        
        NSString* finalstring= [description1 stringByAppendingString:description2];
        
        [articleAbstract appendAttributedString:
         [[NSAttributedString alloc] initWithString: finalstring]];
    

    But when i try this but it now it ignores the both functions.
     
  12. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #12
    Could you tell us what input you're testing it with, what output you're expecting, and what output you're actually getting? (And might I suggest writing a unit test after you provide us with that?)
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    I've asked for that from the OP twice now and still have not received an answer. Third times a charm, maybe?
     

Share This Page