Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnnyfla123

macrumors newbie
Original poster
Jun 15, 2013
21
0
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
 
...but i need the data to go through both of them...

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?
 
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
 
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?
 
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?


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
 
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
 
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
 
Last edited by a moderator:
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.
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.
 
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.
 
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.

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?)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.