daveMac
daveMac

Reputation: 3041

Parsing Main Body Of RSS Feed

I am trying to figure out if I can somehow get the main body of my Wordpress RSS feed. Even though I have my wordpress settings to show the full text of each post, when I parse it on the iPhone, I am only getting the summary.

Here is a sample of my code:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    currentElement = [elementName copy];

    if ([elementName isEqualToString:@"item"]) {
        item = [[NSMutableDictionary alloc] init];
        self.currentTitle = [[NSMutableString alloc] init];
        self.currentSummary = [[NSMutableString alloc] init];
    }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    if ([elementName isEqualToString:@"item"]) {
        [item setObject:self.currentTitle forKey:@"title"];
        [item setObject:self.currentSummary forKey:@"summary"];


        [items addObject:[item copy]];
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    if ([currentElement isEqualToString:@"title"]) {
        [self.currentTitle appendString:string];
    } else if ([currentElement isEqualToString:@"description"]) {
        [self.currentSummary appendString:string];
    } 
}

This has been pieced together from examples. I have verified that the main body is there by making the whole thing a string and logging it. I still don't have any idea how in the world I know what tag or title to use. For example: "item", "description", "pubDate", "title". How does anyone know what tag to use? Please help.

Upvotes: 1

Views: 358

Answers (1)

alxmitch
alxmitch

Reputation: 633

The full text of the post should be in the <content:encoded> element within each <item>.

This page provides a good discussion of various methods of parsing XML in iOS - it might be easier to use one of DOM based parsers if you're not dealing with lots of content.

Upvotes: 2

Related Questions