Using NSXMLParser to parse Vimeo XML on iPhone.

Posted by Sonny Fazio on Stack Overflow See other posts from Stack Overflow or by Sonny Fazio
Published on 2010-05-20T12:27:08Z Indexed on 2010/05/20 12:30 UTC
Read the original article Hit count: 288

Filed under:
|
|

Hello, I'm working on an iPhone app that will use Vimeo Simple API to give me a listing our videos by a certain user, in a convenient TableView format. I'm new to Parsing XML and have tried TouchXML, TinyXML, and now NSXMLParser with no luck. Most tutorials on parsing XML are for a blog, and not for an API XML sheet. I've tried modifying the blog parsers to search for the specific tags, but it doesn't seem to work.

Right now I'm working with NSXMLParser and it seems to correctly find the value of an XML tag, but when it goes to append it to a NSMutableString, it writes a whole bunch of nulls in between it. I'm using a tutorial from theappleblog and modifying it to work with Vimeo API

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

if ([currentElement isEqualToString:@"video_title"]) { NSLog(@"String: %@",string); [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"video_url"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"video_description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"date"]) { [currentDate appendString:string]; }

Here is the nulls it writes: http://grab.by/grabs/92d9cfc2df4fac3fe6579493b1a8e89f.png

Then when it finishes, it has to add the NSMutableStrings into a NSMutableDictionary

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{   
//NSLog(@"found this element: %@", elementName);

currentElement = [elementName copy];

if ([elementName isEqualToString:@"item"]) { // clear out our story item caches... item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; }

}

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

NSLog(@"Title: %@",currentTitle); if ([elementName isEqualToString:@"item"]) {// save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"video_title"]; NSLog(@"Current Title%@", currentTitle); [item setObject:currentLink forKey:@"video_url"]; [item setObject:currentSummary forKey:@"video_description"]; [item setObject:currentDate forKey:@"date"];

[stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } }

I would really appreciate it if someone has any advance

© Stack Overflow or respective owner

Related posts about iphone

Related posts about Xml