Search Results

Search found 126 results on 6 pages for 'nsxmlparser'.

Page 1/6 | 1 2 3 4 5 6  | Next Page >

  • NSXMLParser Memory Allocation Efficiency for the iPhone

    - by Staros
    Hello, I've recently been playing with code for an iPhone app to parse XML. Sticking to Cocoa, I decided to go with the NSXMLParser class. The app will be responsible for parsing 10,000+ "computers", all which contain 6 other strings of information. For my test, I've verified that the XML is around 900k-1MB in size. My data model is to keep each computer in an NSDictionary hashed by a unique identifier. Each computer is also represented by a NSDictionary with the information. So at the end of the day, I end up with a NSDictionary containing 10k other NSDictionaries. The problem I'm running into isn't about leaking memory or efficient data structure storage. When my parser is done, the total amount of allocated objects only does go up by about 1MB. The problem is that while the NSXMLParser is running, my object allocation is jumping up as much as 13MB. I could understand 2 (one for the object I'm creating and one for the raw NSData) plus a little room to work, but 13 seems a bit high. I can't imaging that NSXMLParser is that inefficient. Thoughts? Code... The code to start parsing... NSXMLParser *parser = [[NSXMLParser alloc] initWithData: data]; [parser setDelegate:dictParser]; [parser parse]; output = [[dictParser returnDictionary] retain]; [parser release]; [dictParser release]; And the parser's delegate code... -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if(mutableString) { [mutableString release]; mutableString = nil; } mutableString = [[NSMutableString alloc] init]; } -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(self.mutableString) { [self.mutableString appendString:string]; } } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"size"]){ //The initial key, tells me how many computers returnDictionary = [[NSMutableDictionary alloc] initWithCapacity:[mutableString intValue]]; } if([elementName isEqualToString:hashBy]){ //The unique identifier if(mutableDictionary){ [mutableDictionary release]; mutableDictionary = nil; } mutableDictionary = [[NSMutableDictionary alloc] initWithCapacity:6]; [returnDictionary setObject:[NSDictionary dictionaryWithDictionary:mutableDictionary] forKey:[NSMutableString stringWithString:mutableString]]; } if([fields containsObject:elementName]){ //Any of the elements from a single computer that I am looking for [mutableDictionary setObject:mutableString forKey:elementName]; } } Everything initialized and released correctly. Again, I'm not getting errors or leaking. Just inefficient. Thanks for any thoughts!

    Read the article

  • Iphone NSXMLParser NSCFString memory leak

    - by atticusalien
    I am building an app that parses an rss feed. In the app there are two different types of feeds with different names for the elements in the feed, so I have created an NSXMLParser NSObject that takes the name of the elements of each feed before parsing. Here is my code: NewsFeedParser.h #import @interface NewsFeedParser : NSObject { NSInteger NewsSelectedCategory; NSXMLParser *NSXMLNewsParser; NSMutableArray *newsCategories; NSMutableDictionary *NewsItem; NSMutableString *NewsCurrentElement, *NewsCurrentElement1, *NewsCurrentElement2, *NewsCurrentElement3; NSString *NewsItemType, *NewsElement1, *NewsElement2, *NewsElement3; NSInteger NewsNumElements; } - (void) parseXMLFileAtURL:(NSString *)URL; @property(nonatomic, retain) NSString *NewsItemType; @property(nonatomic, retain) NSString *NewsElement1; @property(nonatomic, retain) NSString *NewsElement2; @property(nonatomic, retain) NSString *NewsElement3; @property(nonatomic, retain) NSMutableArray *newsCategories; @property(assign, nonatomic) NSInteger NewsNumElements; @end NewsFeedParser.m #import "NewsFeedParser.h" @implementation NewsFeedParser @synthesize NewsItemType; @synthesize NewsElement1; @synthesize NewsElement2; @synthesize NewsElement3; @synthesize newsCategories; @synthesize NewsNumElements; - (void)parserDidStartDocument:(NSXMLParser *)parser{ } - (void)parseXMLFileAtURL:(NSString *)URL { newsCategories = [[NSMutableArray alloc] init]; URL = [URL stringByReplacingOccurrencesOfString:@" " withString:@""]; URL = [URL stringByReplacingOccurrencesOfString:@"\n" withString:@""]; URL = [URL stringByReplacingOccurrencesOfString:@" " withString:@""]; //you must then convert the path to a proper NSURL or it won't work NSURL *xmlURL = [NSURL URLWithString:URL]; // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error // this may be necessary only for the toolchain [[NSURLCache sharedURLCache] setMemoryCapacity:0]; [[NSURLCache sharedURLCache] setDiskCapacity:0]; NSXMLNewsParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks. [NSXMLNewsParser setDelegate:self]; // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser. [NSXMLNewsParser setShouldProcessNamespaces:NO]; [NSXMLNewsParser setShouldReportNamespacePrefixes:NO]; [NSXMLNewsParser setShouldResolveExternalEntities:NO]; [NSXMLNewsParser parse]; [NSXMLNewsParser release]; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]]; NSLog(@"error parsing XML: %@", errorString); UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [errorAlert show]; [errorAlert release]; [errorString release]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ NewsCurrentElement = [elementName copy]; if ([elementName isEqualToString:NewsItemType]) { // clear out our story item caches... NewsItem = [[NSMutableDictionary alloc] init]; NewsCurrentElement1 = [[NSMutableString alloc] init]; NewsCurrentElement2 = [[NSMutableString alloc] init]; if(NewsNumElements == 3) { NewsCurrentElement3 = [[NSMutableString alloc] init]; } } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if ([elementName isEqualToString:NewsItemType]) { // save values to an item, then store that item into the array... [NewsItem setObject:NewsCurrentElement1 forKey:NewsElement1]; [NewsItem setObject:NewsCurrentElement2 forKey:NewsElement2]; if(NewsNumElements == 3) { [NewsItem setObject:NewsCurrentElement3 forKey:NewsElement3]; } [newsCategories addObject:[[NewsItem copy] autorelease]]; [NewsCurrentElement release]; [NewsCurrentElement1 release]; [NewsCurrentElement2 release]; if(NewsNumElements == 3) { [NewsCurrentElement3 release]; } [NewsItem release]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([NewsCurrentElement isEqualToString:NewsElement1]) { [NewsCurrentElement1 appendString:string]; } else if ([NewsCurrentElement isEqualToString:NewsElement2]) { [NewsCurrentElement2 appendString:string]; } else if (NewsNumElements == 3 && [NewsCurrentElement isEqualToString:NewsElement3]) { [NewsCurrentElement3 appendString:string]; } } - (void)dealloc { [super dealloc]; [newsCategories release]; [NewsItemType release]; [NewsElement1 release]; [NewsElement2 release]; [NewsElement3 release]; } When I create an instance of the class I do like so: NewsFeedParser *categoriesParser = [[NewsFeedParser alloc] init]; if(newsCat == 0) { categoriesParser.NewsItemType = @"article"; categoriesParser.NewsElement1 = @"category"; categoriesParser.NewsElement2 = @"catid"; } else { categoriesParser.NewsItemType = @"article"; categoriesParser.NewsElement1 = @"category"; categoriesParser.NewsElement2 = @"feedUrl"; } [categoriesParser parseXMLFileAtURL:feedUrl]; newsCategories = [[NSMutableArray alloc] initWithArray:categoriesParser.newsCategories copyItems:YES]; [self.tableView reloadData]; [categoriesParser release]; If I run the app with the leaks instrument, the leaks point to the [NSXMLNewsParser parse] call in the NewsFeedParser.m. Here is a screen shot of the Leaks instrument with the NSCFStrings leaking: http://img139.imageshack.us/img139/3997/leaks.png For the life of me I can't figure out where these leaks are coming from. Any help would be greatly appreciated.

    Read the article

  • [SOLVED] Iphone NSXMLParser NSCFString memory leak

    - by atticusalien
    I am building an app that parses an rss feed. In the app there are two different types of feeds with different names for the elements in the feed, so I have created an NSXMLParser NSObject that takes the name of the elements of each feed before parsing. Here is my code: NewsFeedParser.h #import @interface NewsFeedParser : NSObject { NSInteger NewsSelectedCategory; NSXMLParser *NSXMLNewsParser; NSMutableArray *newsCategories; NSMutableDictionary *NewsItem; NSMutableString *NewsCurrentElement, *NewsCurrentElement1, *NewsCurrentElement2, *NewsCurrentElement3; NSString *NewsItemType, *NewsElement1, *NewsElement2, *NewsElement3; NSInteger NewsNumElements; } - (void) parseXMLFileAtURL:(NSString *)URL; @property(nonatomic, retain) NSString *NewsItemType; @property(nonatomic, retain) NSString *NewsElement1; @property(nonatomic, retain) NSString *NewsElement2; @property(nonatomic, retain) NSString *NewsElement3; @property(nonatomic, retain) NSMutableArray *newsCategories; @property(assign, nonatomic) NSInteger NewsNumElements; @end NewsFeedParser.m #import "NewsFeedParser.h" @implementation NewsFeedParser @synthesize NewsItemType; @synthesize NewsElement1; @synthesize NewsElement2; @synthesize NewsElement3; @synthesize newsCategories; @synthesize NewsNumElements; - (void)parserDidStartDocument:(NSXMLParser *)parser{ } - (void)parseXMLFileAtURL:(NSString *)URL { newsCategories = [[NSMutableArray alloc] init]; URL = [URL stringByReplacingOccurrencesOfString:@" " withString:@""]; URL = [URL stringByReplacingOccurrencesOfString:@"\n" withString:@""]; URL = [URL stringByReplacingOccurrencesOfString:@" " withString:@""]; //you must then convert the path to a proper NSURL or it won't work NSURL *xmlURL = [NSURL URLWithString:URL]; // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error // this may be necessary only for the toolchain [[NSURLCache sharedURLCache] setMemoryCapacity:0]; [[NSURLCache sharedURLCache] setDiskCapacity:0]; NSXMLNewsParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks. [NSXMLNewsParser setDelegate:self]; // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser. [NSXMLNewsParser setShouldProcessNamespaces:NO]; [NSXMLNewsParser setShouldReportNamespacePrefixes:NO]; [NSXMLNewsParser setShouldResolveExternalEntities:NO]; [NSXMLNewsParser parse]; [NSXMLNewsParser release]; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]]; NSLog(@"error parsing XML: %@", errorString); UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [errorAlert show]; [errorAlert release]; [errorString release]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ NewsCurrentElement = [elementName copy]; if ([elementName isEqualToString:NewsItemType]) { // clear out our story item caches... NewsItem = [[NSMutableDictionary alloc] init]; NewsCurrentElement1 = [[NSMutableString alloc] init]; NewsCurrentElement2 = [[NSMutableString alloc] init]; if(NewsNumElements == 3) { NewsCurrentElement3 = [[NSMutableString alloc] init]; } } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if ([elementName isEqualToString:NewsItemType]) { // save values to an item, then store that item into the array... [NewsItem setObject:NewsCurrentElement1 forKey:NewsElement1]; [NewsItem setObject:NewsCurrentElement2 forKey:NewsElement2]; if(NewsNumElements == 3) { [NewsItem setObject:NewsCurrentElement3 forKey:NewsElement3]; } [newsCategories addObject:[[NewsItem copy] autorelease]]; [NewsCurrentElement release]; [NewsCurrentElement1 release]; [NewsCurrentElement2 release]; if(NewsNumElements == 3) { [NewsCurrentElement3 release]; } [NewsItem release]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([NewsCurrentElement isEqualToString:NewsElement1]) { [NewsCurrentElement1 appendString:string]; } else if ([NewsCurrentElement isEqualToString:NewsElement2]) { [NewsCurrentElement2 appendString:string]; } else if (NewsNumElements == 3 && [NewsCurrentElement isEqualToString:NewsElement3]) { [NewsCurrentElement3 appendString:string]; } } - (void)dealloc { [super dealloc]; [newsCategories release]; [NewsItemType release]; [NewsElement1 release]; [NewsElement2 release]; [NewsElement3 release]; } When I create an instance of the class I do like so: NewsFeedParser *categoriesParser = [[NewsFeedParser alloc] init]; if(newsCat == 0) { categoriesParser.NewsItemType = @"article"; categoriesParser.NewsElement1 = @"category"; categoriesParser.NewsElement2 = @"catid"; } else { categoriesParser.NewsItemType = @"article"; categoriesParser.NewsElement1 = @"category"; categoriesParser.NewsElement2 = @"feedUrl"; } [categoriesParser parseXMLFileAtURL:feedUrl]; newsCategories = [[NSMutableArray alloc] initWithArray:categoriesParser.newsCategories copyItems:YES]; [self.tableView reloadData]; [categoriesParser release]; If I run the app with the leaks instrument, the leaks point to the [NSXMLNewsParser parse] call in the NewsFeedParser.m. Here is a screen shot of the Leaks instrument with the NSCFStrings leaking: http://img139.imageshack.us/img139/3997/leaks.png For the life of me I can't figure out where these leaks are coming from. Any help would be greatly appreciated.

    Read the article

  • NSXMLParser & memory leaks

    - by HBR
    Hi, I am parsing an XML file using a custom class that instanciates & uses NSXMLParser. On the first call everything is fine but on the second, third and later calls Instruments show tens of memory leaks on certain lines inside didEndElement, didEndElement and foundCharacters functions. I googled it and found some people having this issue, but I didn't find anything that could really help me. My Parser class looks like this : Parser.h @interface XMLParser : NSObject { NSMutableArray *data; NSMutableString *currentValue; NSArray *xml; NSMutableArray *videos; NSMutableArray *photos; NSXMLParser *parser; NSURLConnection *feedConnection; NSMutableData *downloadedData; Content *content; Video *video; BOOL nowPhoto; BOOL nowVideo; BOOL finished; BOOL webTV; } -(void)parseXML:(NSURL*)xmlURL; -(int)getCount; -(NSArray*)getData; //- (void)handleError:(NSError *)error; //@property(nonatomic, retain) NSMutableString *currentValue; @property(nonatomic, retain) NSURLConnection *feedConnection; @property(nonatomic, retain) NSMutableData *downloadedData; @property(nonatomic, retain) NSArray *xml; @property(nonatomic, retain) NSXMLParser *parser; @property(nonatomic, retain) NSMutableArray *data; @property(nonatomic, retain) NSMutableArray *photos; @property(nonatomic, retain) NSMutableArray *videos; @property(nonatomic, retain) Content *content; @property(nonatomic, retain) Video *video; @property(nonatomic) BOOL finished; @property(nonatomic) BOOL nowPhoto; @property(nonatomic) BOOL nowVideo; @property(nonatomic) BOOL webTV; @end Parser.m #import "Content.h" #import "Video.h" #import "Parser.h" #import <CFNetwork/CFNetwork.h> @implementation XMLParser @synthesize xml, parser, finished, nowPhoto, nowVideo, webTV; @synthesize feedConnection, downloadedData, data, content, photos, videos, video; -(void)parseXML:(NSURL*)xmlURL { /* NSURLRequest *req = [NSURLRequest requestWithURL:xmlURL]; self.feedConnection = [[[NSURLConnection alloc] initWithRequest:req delegate:self] autorelease]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; */ [[NSURLCache sharedURLCache] setMemoryCapacity:0]; [[NSURLCache sharedURLCache] setDiskCapacity:0]; NSXMLParser *feedParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; //NSXMLParser *feedParser = [[NSXMLParser alloc] initWithData:theXML]; [self setParser:feedParser]; [feedParser release]; [[self parser] setDelegate:self]; [[self parser] setShouldResolveExternalEntities:YES]; [[self parser] parse]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"articles"]) { self.finished = NO; self.nowPhoto = NO; self.nowVideo = NO; self.webTV = NO; if (!data) { NSMutableArray *tmp = [[NSMutableArray alloc] init]; [self setData:tmp]; [tmp release]; return ; } } if ([elementName isEqualToString:@"WebTV"]) { self.finished = NO; self.nowPhoto = NO; self.nowVideo = NO; self.webTV = YES; if (!data) { NSMutableArray *tmp = [[NSMutableArray alloc] init]; [self setData:tmp]; [tmp release]; return ; } } if ([elementName isEqualToString:@"photos"]) { if (!photos) { NSMutableArray *tmp = [[NSMutableArray alloc] init]; [self setPhotos:tmp]; [tmp release]; return; } } if ([elementName isEqualToString:@"videos"]) { if (!videos) { NSMutableArray *tmp = [[NSMutableArray alloc] init]; [self setVideos:tmp]; [tmp release]; return; } } if ([elementName isEqualToString:@"photo"]) { self.nowPhoto = YES; self.nowVideo = NO; } if ([elementName isEqualToString:@"video"]) { self.nowPhoto = NO; self.nowVideo = YES; } if ([elementName isEqualToString:@"WebTVItem"]) { if (!video) { Video *tmp = [[Video alloc] init]; [self setVideo:tmp]; [tmp release]; } NSString *videoId = [attributeDict objectForKey:@"id"]; [[self video] setVideoId:[videoId intValue]]; } if ([elementName isEqualToString:@"article"]) { if (!content) { Content *tmp = [[Content alloc] init]; [self setContent:tmp]; [tmp release]; } NSString *contentId = [attributeDict objectForKey:@"id"]; [[self content] setContentId:[contentId intValue]]; return; } if ([elementName isEqualToString:@"category"]) { NSString *categoryId = [attributeDict objectForKey:@"id"]; NSString *parentId = [attributeDict objectForKey:@"parent"]; [[self content] setCategoryId:[categoryId intValue]]; [[self content] setParentId:[parentId intValue]]; categoryId = nil; parentId = nil; return; } if ([elementName isEqualToString:@"vCategory"]) { NSString *categoryId = [attributeDict objectForKey:@"id"]; NSString *parentId = [attributeDict objectForKey:@"parent"]; [[self video] setCategoryId:[categoryId intValue]]; [[self video] setParentId:[parentId intValue]]; categoryId = nil; parentId = nil; return; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if (!currentValue) { currentValue = [[NSMutableString alloc] initWithCapacity:1000]; } if (currentValue != @"\n") [currentValue appendString:string]; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { NSString *cleanValue = [currentValue stringByReplacingOccurrencesOfString:@"\n" withString:@""] ; if ([elementName isEqualToString:@"articles"]) { self.finished = YES; //[content release]; } if ([elementName isEqualToString:@"article"]) { [[self data] addObject:[self content]]; [self setContent:nil]; [self setPhotos:nil]; [self setVideos:nil]; /* [content release]; content = nil; [videos release]; videos = nil; [photos release]; photos = nil; */ } if ([elementName isEqualToString:@"WebTVItem"]) { [[self data] addObject:[self video]]; [self setVideo:nil]; //[video release]; //video = nil; } if ([elementName isEqualToString:@"title"]) { //NSLog(@"Tit: %@",cleanValue); [[self content] setTitle:cleanValue]; } if ([elementName isEqualToString:@"vTitle"]) { [[self video] setTitle:cleanValue]; } if ([elementName isEqualToString:@"link"]) { //NSURL *url = [[NSURL alloc] initWithString:cleanValue] ; [[self content] setUrl:[NSURL URLWithString:cleanValue]]; [[self content] setLink: cleanValue]; //[url release]; //url = nil; } if ([elementName isEqualToString:@"vLink"]) { [[self video] setLink:cleanValue]; [[self video] setUrl:[NSURL URLWithString:cleanValue]]; } if ([elementName isEqualToString:@"teaser"]) { NSString *tmp = [cleanValue stringByReplacingOccurrencesOfString:@"##BREAK##" withString:@"\n"]; [[self content] setTeaser:tmp]; tmp = nil; } if ([elementName isEqualToString:@"content"]) { NSString *tmp = [cleanValue stringByReplacingOccurrencesOfString:@"##BREAK##" withString:@"\n"]; [[self content] setContent:tmp]; tmp = nil; } if ([elementName isEqualToString:@"category"]) { [[self content] setCategory:cleanValue]; } if ([elementName isEqualToString:@"vCategory"]) { [[self video] setCategory:cleanValue]; } if ([elementName isEqualToString:@"date"]) { [[self content] setDate:cleanValue]; } if ([elementName isEqualToString:@"vDate"]) { [[self video] setDate:cleanValue]; } if ([elementName isEqualToString:@"thumbnail"]) { [[self content] setThumbnail:[NSURL URLWithString:cleanValue]]; [[self content] setThumbnailURL:cleanValue]; } if ([elementName isEqualToString:@"vThumbnail"]) { [[self video] setThumbnailURL:cleanValue]; [[self video] setThumbnail:[NSURL URLWithString:cleanValue]]; } if ([elementName isEqualToString:@"vDirectLink"]){ [[self video] setDirectLink: cleanValue]; } if ([elementName isEqualToString:@"preview"]){ [[self video] setPreview: cleanValue]; } if ([elementName isEqualToString:@"thumbnail_position"]){ [[self content] setThumbnailPosition: cleanValue]; } if ([elementName isEqualToString:@"url"]) { if (self.nowPhoto == YES) { [[self photos] addObject:cleanValue]; } else if (self.nowVideo == YES) { [[self videos] addObject:cleanValue]; } } if ([elementName isEqualToString:@"photos"]) { [[self content] setPhotos:[self photos]]; //[photos release]; //photos = nil; self.nowPhoto = NO; } if ([elementName isEqualToString:@"videos"]) { [[self content] setVideos:[self videos]]; //[videos release]; //videos = nil; self.nowVideo = NO; } //[cleanValue release]; //cleanValue = nil; [currentValue release]; currentValue = nil; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } -(NSArray*)getData { return data; } -(int)getCount { return [data count]; } - (void)dealloc { [parser release]; //[data release]; //[photos release]; //[videos release]; //[video release]; //[content release]; [currentValue release]; [super dealloc]; } @end Somewhere in my code, I create an instance of this class : XMLParser* feed = [[XMLParser alloc] init]; [self setRssParser:feed]; [feed release]; // Parse feed NSString *url = [NSString stringWithFormat:@"MyXMLURL"]; [[self rssParser] parseXML:[NSURL URLWithString:url]]; Now the problem is that after the first (which has zero leaks), instruments shows leaks in too many parts like this one (they are too much to enumerate them all, but all the calls look the same, I made the leaking line bold) : in didEndElement : if ([elementName isEqualToString:@"link"]) { // THIS LINE IS LEAKING => INSTRUMENTS SAYS IT IS A NSCFString LEAK [self content] setUrl:[NSURL URLWithString:cleanValue]]; [[self content] setLink: cleanValue]; } Any idea how to fix this pealse ? Could this be the same problem as the one mentioned (as an apple bug) by Lee Amtrong here :http://stackoverflow.com/questions/1598928/nsxmlparser-leaking

    Read the article

  • NSXMLParser + encoding="windows-1257"

    - by Moze
    So i'm making small program and it download ziped XML database file that is ~30 MB size (unziped). As I understand there is only way with such big files on iPhone, it's to use NSXMLParser. But that file is encoded with windows-1257 format and NSXMLParser does not eat files like that. What can I do? Is there a way to change file encoding on iphone or make NSXMLParser work with other then UTF8 encoded files?

    Read the article

  • OO model for nsxmlparser when delegate is not self

    - by richard
    Hi, I am struggling with the correct design for the delegates of nsxmlparser. In order to build my table of Foos, I need to make two types of webservice calls; one for the whole table and one for each row. It's essentially a master-query then detail-query, except the master-query-result-xml doesn't return enough information so i then need to query the detail for each row. I'm not dealing with enormous amounts of data. Anyway - previously I've just used NSXMLParser *parser = [[NSXMLParser alloc]init]; [parser setDelegate:self]; [parser parse]; and implemented all the appropriate delegate methods in whatever class i'm in. In attempt at cleanliness, I've now created two separate delegate classes and done something like: NSXMLParser *xp = [[NSXMLParser alloc]init]; MyMasterXMLParserDelegate *masterParserDelegate = [[MyMasterXMLParser]alloc]init]; [xp setDelegate:masterParserDelegate]; [xp parse]; In addition to being cleaner (in my opinion, at least), it also means each of the -parser:didStartElement implementations don't spend most of the time trying to figure out which xml they're parsing. So now the real crux of the problem. Before i split out the delegates, i had in the main class that was also implementing the delegate methods, a class-level NSMutableArray that I would just put my objects-created-from-xml in when -parser:didEndElement found the 'end' of each record. Now the delegates are in separate classes, I can't figure out how to have the -parser:didEndElement in the 'detail' delegate class "return" the created object to the calling class. At least, not in a clean OO way. I'm sure i could do it with all sorts of nasty class methods. Does the question make sense? Thanks.

    Read the article

  • Using NSXMLParser with CDATA

    - by Robb
    I'm parsing an RSS feed with NSXMLParser and it's working fine for the title and other strings but one of the elements is an image thats like <!CDATA <a href="http:image..etc> How do I add that as my cell image in my table view? Would I define that as an image type? This is what i'm using to do my parsing: - (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(@"ended element: %@", elementName); if ([elementName isEqualToString:@"item"]) { // save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"title"]; [item setObject:currentLink forKey:@"link"]; [item setObject:currentSummary forKey:@"description"]; [item setObject:currentDate forKey:@"date"]; [stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([currentElement isEqualToString:@"title"]) { [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"link"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"pubDate"]) { [currentDate appendString:string]; } }

    Read the article

  • Parsing ISO-8859-1 w/ NSXmlParser

    - by Travis
    I am usin the nsxmlparser and am wondering how I can parse ISO-8859-1 correctly into an NSString. Currently, I am getting results w/ Â for two-byte characters. The XML I'm using (not created by me) starts with <?xml version="1.0" encoding="ISO-8859-1"?> Here are the basic calls I'm using (omitted the NSThread calls). NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:sampleFileName ofType:@"xml"]; NSString *xmlFileContents = [NSString stringWithContentsOfFile:xmlFilePath encoding:NSUTF8StringEncoding error:nil]; NSData *data = [xmlFileContents dataUsingEncoding:NSUTF8StringEncoding]; NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; [parser setDelegate:self]; [parser parse];

    Read the article

  • NSXMLParser and Geonames

    - by Xcoder
    I'm trying to parse a call from Geonames with NSXMLParser in the iPhone SDK. I've used this before but for some reason I'm getting an empty dictionary back even though I get results back in a web browser. Can someone please point out what I may be doing wrong. Below is the code I'm using and the results that comes back pasting it in a browser. Thanks in advance #pragma mark - #pragma mark - Parcer Services -(void)beginLoadingFeed{ //[self startLoadingWithMessage:@"Loading Results...."]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadFeed) object:nil]; [operationQueue addOperation:operation]; [operation release]; } - (void)loadFeed{ NSString *path = [NSString stringWithFormat:@"http://ws.geonames.org/postalCodeSearch?placename=%@&long&maxRows=20",self.location]; [Logger log:@"Geonames Query: %@",path]; [self parseXMLFileAtURL:path]; [self performSelectorOnMainThread:@selector(didfinishedLoadingFeed) withObject:nil waitUntilDone:YES]; } -(void)didfinishedLoadingFeed{ } - (void)parserDidStartDocument:(NSXMLParser *)parser{ [Logger log:@"found file and started parsing"]; } //Called when the parser runs into an open tag (<tag>) - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"code"]) { currentResult = [NSMutableDictionary dictionary]; } else { currentElement = [elementName copy]; } } //This is just to resolve random HTML entities - (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName:(NSString *)entityName systemID:(NSString *)systemID { return [entityName dataUsingEncoding:NSASCIIStringEncoding]; } - (void)parseXMLFileAtURL:(NSString *)URL{ self.results = [[[NSMutableArray alloc] init] autorelease]; NSURL *xmlURL = [NSURL URLWithString:URL]; NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; [parser setDelegate:self]; [parser parse]; [parser autorelease]; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { NSString * errorString = [NSString stringWithFormat:@"Unable to connect to web site (Error code %i )", [parseError code]]; [Logger log:@"error parsing : %@", errorString]; [self stopLoadingView]; [self showMessage:@"Error loading content" withTitle:@"Error Loading"]; } /*** Called when the parser runs into a close tag (</tag>). If it is the Result tag that is closing, we should add the currentResult to the array, and then forget about it ***/ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementName isEqualToString:@"code"]) { [self.results addObject:currentResult]; currentResult = nil; } } - (void)parserDidEndDocument:(NSXMLParser *)parser { [Logger log:@"all done!"]; [Logger log:@"results array has %d items", [self.results count]]; [Logger log:@"Results:%@",results]; [theTableView reloadData]; [self stopLoadingView]; } Below is the result that comes back in a browser using the same call above when doing the search for the term "boston": <?xml version="1.0" encoding="UTF-8" standalone="no"?> <geonames> <totalResultsCount>2808</totalResultsCount> <code> <postalcode>02101</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.370567</lat> <lng>-71.026964</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02108</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.357603</lat> <lng>-71.068432</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02109</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.360027</lat> <lng>-71.054495</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02110</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.357636</lat> <lng>-71.051417</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02111</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.350348</lat> <lng>-71.0629</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02114</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.361111</lat> <lng>-71.06823</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02115</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.342706</lat> <lng>-71.092215</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02116</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.349201</lat> <lng>-71.076798</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02118</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.336162</lat> <lng>-71.072854</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02128</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.364197</lat> <lng>-71.025694</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02199</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.347873</lat> <lng>-71.082543</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02210</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.348921</lat> <lng>-71.046511</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02215</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.347088</lat> <lng>-71.102689</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>22713</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>38.538241</lat> <lng>-78.142285</lng> <adminCode1>VA</adminCode1> <adminName1>Virginia</adminName1> <adminCode2>047</adminCode2> <adminName2>Culpeper</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>24592</postalcode> <name>South Boston</name> <countryCode>US</countryCode> <lat>36.696335</lat> <lng>-78.918829</lng> <adminCode1>VA</adminCode1> <adminName1>Virginia</adminName1> <adminCode2>083</adminCode2> <adminName2>Halifax</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02102</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.338947</lat> <lng>-70.919635</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02103</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.338947</lat> <lng>-70.919635</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02104</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.338947</lat> <lng>-70.919635</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02105</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.338947</lat> <lng>-70.919635</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> <code> <postalcode>02106</postalcode> <name>Boston</name> <countryCode>US</countryCode> <lat>42.354318</lat> <lng>-71.073449</lng> <adminCode1>MA</adminCode1> <adminName1>Massachusetts</adminName1> <adminCode2>025</adminCode2> <adminName2>Suffolk</adminName2> <adminCode3/> <adminName3/> </code> </geonames>

    Read the article

  • NSXMLParser values not being retained.

    - by user574947
    This is similar to my previous question. I didn't get an answer, maybe by changing the question I might get an answer. Here is my parsing code: -(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *) attributeDict { if ([elementName isEqualToString:kimgurl] || [elementName isEqualToString:kone_x] || [elementName isEqualToString:kone_y] || [elementName isEqualToString:kone_radius] || [elementName isEqualToString:ktwo_x] || [elementName isEqualToString:ktwo_y] || [elementName isEqualToString:ktwo_radius]) { elementFound = YES; theItems = [[Items alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:kimgurl]) { theItems.imageURL = self.currentValue; [self.currentValue setString:@""]; } else if([elementName isEqualToString:kone_x]) { theItems.iOne_X = self.currentValue; [self.currentValue setString:@""]; } else if([elementName isEqualToString:kone_y]) { theItems.iOne_Y = self.currentValue; [self.currentValue setString:@""]; } else if([elementName isEqualToString:kone_radius]) { theItems.iOne_Radius = self.currentValue; [self.currentValue setString:@""]; } else if([elementName isEqualToString:ktwo_x]) { theItems.iTwo_X = self.currentValue; [self.currentValue setString:@""]; } else if([elementName isEqualToString:ktwo_y]) { theItems.iTwo_Y = self.currentValue; [self.currentValue setString:@""]; } else if([elementName isEqualToString:ktwo_radius]) { theItems.iTwo_Radius = self.currentValue; [self.currentValue setString:@""]; } } -(void) parserDidEndDocument:(NSXMLParser *)parser { NSLog(@"enddocument: %@", theItems.imageURL); } -(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string { if (elementFound == YES) { if(!currentValue) { currentValue = [NSMutableString string]; } [currentValue appendString: string]; } } When I get to parserDidEndDocument. The theItems class is empty. Here is Items.h #import <Foundation/Foundation.h> @interface Items : NSObject { @private //parsed data NSString *imageURL; NSString *iOne_X; NSString *iOne_Y; NSString *iOne_Radius; NSString *iTwo_X; NSString *iTwo_Y; NSString *iTwo_Radius; } @property (nonatomic, retain) NSString *imageURL; @property (nonatomic, retain) NSString *iOne_X; @property (nonatomic, retain) NSString *iOne_Y; @property (nonatomic, retain) NSString *iOne_Radius; @property (nonatomic, retain) NSString *iTwo_X; @property (nonatomic, retain) NSString *iTwo_Y; @property (nonatomic, retain) NSString *iTwo_Radius; @end here is Items.m #import "Items.h" @implementation Items @synthesize imageURL; @synthesize iOne_X; @synthesize iOne_Y; @synthesize iOne_Radius; @synthesize iTwo_X; @synthesize iTwo_Y; @synthesize iTwo_Radius; -(void)dealloc { [imageURL release]; [iOne_X release]; [iOne_Y release]; [iOne_Radius release]; [iTwo_X release]; [iTwo_Y release]; [iTwo_Radius release]; [super dealloc]; } @end here is my RootViewController.h #import <UIKit/UIKit.h> @class Items; @interface RootViewController : UIViewController <NSXMLParserDelegate> { NSMutableData *downloadData; NSURLConnection *connection; BOOL elementFound; NSMutableString *currentValue; NSMutableDictionary *pictures; //---xml parsing--- NSXMLParser *xmlParser; Items *theItems; NSMutableArray *aItems; } @property (nonatomic, retain) Items *theItems; @property (nonatomic, retain) NSMutableArray *aItems; @property (nonatomic, retain) NSMutableString *currentValue; @property (nonatomic, retain) NSMutableData *downloadData; @property (nonatomic, retain) NSURLConnection *connection; @end xml file example <?xml version="1.0" encoding="utf-8"?> <data> <test> <url>url</url> <one_x>83</one_x> <one_y>187</one_y> <one_radius>80</one_radius> <two_x>183</two_x> <two_y>193</two_y> <two_radius>76</two_radius> </test> </data>

    Read the article

  • iphone's nsxmlparser parsing RSS causes encoding problems

    - by Tankista
    Hi, Im working on simle RSS reader. This reader loads data from internet via this code: NSXMLParser *rss = [[NSXMLParser alloc] initWithURL:[NSURL URLWithString:@"http://twitter.com/statuses/user_timeline/50405236.rss"]]; My problem is with encoding. RSS 2.0 file is supposed to be UTF8 encoded according to encoding attribute in XML file. <?xml version="1.0" encoding="utf-8"?> So when I download URLs content I get text truncated after first occurance of char with diacritics, example: l š c t ž ý á í é, etc. I tried to solve the problem by downloading URL as UTF8 string, I used this code: NSString *rssXmlString = [NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://www.macblog.sk/rss.xml"] encoding:NSUTF8StringEncoding error: nil]; NSData *rssXmlData = [rssXmlString dataUsingEncoding: NSUTF8StringEncoding]; Did not help. Thanx for your responses.

    Read the article

  • How to abort iPhone's NSXMLParser wait

    - by Wayne Lo
    When init the NSXLParser as below: NSXMLParser* xmlParser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlstring]]; if the server is down, it will wait for quite some time before the thread returns. It is really annoying even if I exit the application and restart the application, it will continue to wait with a black screen until it times out. How to I abort the init? Is there a better way to check whether the server is up before calling the parser? Thanks for helping.

    Read the article

  • Web Url contains Spanish Characters which my NSXMLParser is not parsing

    - by mAc
    I am Parsing Web urls from server and storing them in Strings and then displaying it on Webview. But now when i am parsing Spanish words like http://litofinter.es.milfoil.arvixe.com/litofinter/PDF/Presentación_LITOFINTER_(ES).pdf it is accepting it PDF File Name ++++++ http://litofinter.es.milfoil.arvixe.com/litofinter/PDF/Presentaci PDF File Name ++++++ ón_LITOFINTER_(ES).pdf i.e two different strings... i know i have to make small change that is append the string but i am not able to do it now, can anyone help me out. Here is my code :- - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { currentElement = elementName; if([currentElement isEqualToString:@"category"]) { NSLog(@"Current element in Category:- %@",currentElement); obj = [[Litofinter alloc]init]; obj.productsArray = [[NSMutableArray alloc]init]; } if([currentElement isEqualToString:@"Product"]) { obj.oneObj = [[Products alloc]init]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if([currentElement isEqualToString:@"Logo"]) { obj.cLogo=[NSString stringWithFormat:@"%@",string]; NSLog(@"Logo to be saved in Array :- %@",obj.cLogo); } if([currentElement isEqualToString:@"Name"]) { obj.cName=[NSString stringWithFormat:@"%@",string]; NSLog(@"Name to be saved in Array :- %@",string); } if([currentElement isEqualToString:@"cid"]) { obj.cId=(int)[NSString stringWithFormat:@"%@",string]; NSLog(@"CID to be saved in Array :- %@",string); } if([currentElement isEqualToString:@"pid"]) { //obj.oneObj.id = (int)[NSString stringWithFormat:@"%@",oneBook.id]; obj.oneObj.id = (int)[oneBook.id intValue]; } if([currentElement isEqualToString:@"Title"]) { obj.oneObj.title = [NSString stringWithFormat:@"%@",string]; } if([currentElement isEqualToString:@"Thumbnail"]) { obj.oneObj.thumbnail= [NSString stringWithFormat:@"%@",string]; } // problem occuriing while parsing Spanish characters... if([currentElement isEqualToString:@"pdf"]) { obj.oneObj.pdf = [NSString stringWithFormat:@"%@",string]; NSLog(@"PDF File Name ++++++ %@",string); } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"category"]) { NSLog(@"Current element in End Element Category:- %@",currentElement); [TableMutableArray addObject:obj]; } if([elementName isEqualToString:@"Product"]) { [obj.productsArray addObject:obj.oneObj]; } currentElement = @""; } I will be thankful to you.

    Read the article

  • NSXMLParser not parsing attributes. No NSXMLParser Error.

    - by Iris
    I am trying to parse the XML located at this URL: http://www.iglooseat.com/gis_iphone_xml.php?zip=06488 // 1) This method gets invoked when the user presses a button on the Iphone to retrieve the xml data (IBAction)getLocations:(id)sender { NSString *msg=nil; NSString *urlString= [[NSString alloc] initWithFormat:@"http://www.iglooseat.com/gis_iphone_xml.php?zip=%@",zipField.text]; // send the URL NSError *error; [siteList updateLocationsFromURL:urlString parseError:&error]; WPSite *w = [siteList siteAtIndex:0]; // alert user what's in the zipField msg = [[NSString alloc] initWithFormat: @"url to send: %@\n site name: %@" , urlString , w.name]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Debug" message:msg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [urlString release]; [alert show]; [alert release]; [msg release]; } // 2) This function takes the URL and performs XML parsing on the data at that URL. (void)updateLocationsFromURL:(NSString )urlString parseError:(NSError *)error{ /* NSURL class that inherits from NSObject class that provides a way to manipulate URLs and the resources they reference. */ NSURL *url = [[NSURL alloc] initWithString:urlString]; /* initWithContentsOfURL: initializes a newly allocated data object initialized with the data from the location specified by a URL. */ NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url]; // init bool to NO errorConnecting = NO; // release from mem the NSURfile://localhost/Users/icheung/Desktop/WPMap/Classes/WPSite.mL [url release]; // set parser delgate to self [parser setDelegate:self]; // don't process namespace [parser setShouldProcessNamespaces:YES]; // or namespace prefixes [parser setShouldReportNamespacePrefixes:NO]; /* don't care 'bout external (ex. don't perform I/O op's to load external DTD's (Document Type Definitions)) */ [parser setShouldResolveExternalEntities:NO]; // start the event-driven parsing operation [parser parse]; // get NSError object if an error occured during parsing NSError *parseError = [parser parserError]; if(parseError && error) { *error = parseError; NSLog(@"Error code:%d %@", parseError.code, parseError.domain); errorConnecting = YES; } // relase from mem the parser [parser release]; } // 3) In the parser:didStartElement:namespaceURI:qualifiedName:attributes: I attempt to extract the 'state' attribute from a 'marker' element in my xml. When I use the gdb debugger to inspect the contents of attributeDict it is empty and I'm not sure why. (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if(self.parserContentOfCurrentProperty == nil) { NSMutableString *tmp = [[NSMutableString alloc] init]; self.parserContentOfCurrentProperty = tmp; [tmp release]; } [self.parserContentOfCurrentProperty setString:@""]; self.parserNameOfCurrentProperty = elementName; if ([elementName isEqualToString:@"markers"]) { WPSite *tmp = [WPSite alloc]; self.parserCurrentSite = tmp; // retrive value for attribute NSString *stateAttribute = [attributeDict valueForKey:@"state"]; if (stateAttribute) { [self.parserCurrentSite setState:stateAttribute]; } // add this site to the site list [siteList addObject:self.parserCurrentSite]; return; } }

    Read the article

  • How to hadle a tags inside another tags in NSXMLParser

    - by SimpleMan
    I have a file: <xml> <component>something <system>somethingDeeper <value>somethingDeepest</value> </system> </component> <component>somethinfDifferent <value>somethingDifferentDeeper</value> </component> <value>somethingNew</value> </xml> So i want to distinguish what is inside another tag (ex. <system>) what is not. How to do this with NSXMLParser ? I currently use BOOL ivar's but this is a lot of tags and this is not as elegant as i want it to be. I know that NSXMLParser is a SAX parser and i understand that. In above example I will be enter to didEndElement method three times with: elementName equal value Is there a more elegant way to distinguish what entry was from <component> tag above what not?

    Read the article

  • Speed of NSScanner vs NSXMLParser?

    - by Chris
    I have an iPhone App that reads in an XML file, then pulls out the necessary data by looping through an NSScanner. The XML is not particularly long. I am wondering if it would be worth the work to implement NSXMLParser in place of using NSScanner, if I will see any real improvement in speed?

    Read the article

  • NSXMLParser on the iPhone, how do i use it given a xml file (newb here :\)

    - by Kenneth
    Hey guys, was wondering how do i use the NSXML parser. so lets say given i have a simple xml file with elements like 1/1/1000 14:15:16 How could i use the NSXMLParser to parse the XML File(Its on locally btw, desktop), check through each element and store each of them in an array either to be displayed/used later? I was looking through some documentation about it and i absolutely have no idea on how to use the parser i know that there are 3 methods(or more ,please correct me if im wrong) that can be overridden -..etc didStartElement -..etc didEndElement -..etc foundCharacters

    Read the article

  • iPhone NSXMLParser parsing string and storing in a NSNumber variable and different data types

    - by anubhav
    Hi, I am trying to parse a XML File using NSXMLParser, I also have a Container class, in which I have a few instance variables. One of the elements that I am trying to parse in the XML is: <book sn="32.859669048339128" pn="-116.917800670489670"> I am trying to save the value of sn and pn in an instance variable of object Container: NSNumber *sn, NSNumber *pn. I want it so that when my parser get the attributeValues it can save it as a Double (or float) in those NSNumber pointers. Right now, all it does it just saves a string to the NSNumber. The Parser Code looks like this: if([elementName isEqualToString:@"book"]){ container = [[Container alloc] init]; container.sn=[attributeDict objectForKey:@"sn"]; container.pn=[attributeDict objectForKey:@"pn"]; } I want it so that the type of container.sn is initialized to a float or double. Any ideas how to do this? Thanks in advance!

    Read the article

  • xml parsing using nsxmlParser in iphone

    - by filthynight
    hi all, I have a problem in parsing xml from google api, the api xml looks like this ....... Now the problem is that first of all, the tags are different, like first parent tag name is "abc" and second parent tag is "efg", further more the inner tags are different as well. i have modified code got from web that it parses another url, but in this case since the tags keeps on changing it does not work. the url = "http://www.google.com/ig/api?weather=anaheim,ca" Source Code (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); if (currentElement) { [currentElement release]; currentElement = nil; } currentElement = [elementName copy]; NSString *thisOwner = [attributeDict objectForKey:@"data"]; NSLog(@"element Name-------: %@", thisOwner); if ([elementName isEqualToString:@"forecast_information"]) //|| [elementName isEqualToString:@"current_conditions"] || [elementName isEqualToString:@"forecast_conditions"]) { // clear out our story item caches... //NSString *nm = [[attributeDict objectForKey:@"city"] stringValue]; //NSLog(@"value...%@",nm); item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; [item setObject:currentLink forKey:@"postal_code"]; [item setObject:currentSummary forKey:@"current_date_time"]; [item setObject:currentDate forKey:@"unit_system"]; NSLog(@"adding story: %@", currentTitle); [stories addObject:[item copy]]; } } I have another function didEndElement where the values are assigned in the array, but i could not figure out how to assign values of an attribute. Can somebody please help me in this regards Thanks!

    Read the article

  • NSXMLparser errorcode 5

    - by sukitha
    Hi, I'm using Amazon's simpledb in my app. When parsing xml it gives an error with the code 5. ie. NSXMLParserErrorDomain error 5. Sometimes it works fine and without any significant change in the navigation is gives that error. Again it works fine when i restart the app several times without doing any changes to the code or navigation in the system. I cant figure out the reason why this happens. thanks

    Read the article

  • NSXMLParser rss issue NSXMLParserInvalidCharacterError

    - by Chris Van Buskirk
    NSXMLParserInvalidCharacterError # 9 This is the error I get when I hit a weird character (like quotes copied and pasted from word to the web form, that end up in the feed). The feed I am using is not giving an encoding, and their is no hope for me to get them to change that. This is all I get in the header: < ?xml version="1.0"? < rss version="2.0" What can I do about illegal characters when parsing feeds? Do I sweep the data prior to the parse? Is there something I am missing in the API? Has anyone dealt with this issue?

    Read the article

  • NSXMLParser with multiple attributes

    - by mitb67
    Hi. I have the following XML (doing an app for iPhone): <Row> <Field name="employee_id_disp">00070431</Field> <Field name="given_name">John</Field> <Field name="family_name">Doe</Field> </Row> ... How can I retrieve values only for one of the attributes, for example value "John" for attribute name="given_name" ? Thanks for answers.

    Read the article

  • How can I release this NSXMLParser without crashing my app?

    - by prendio2
    Below is the @interface for an MREntitiesConverter object I use to strip all html tags from a string using an NSXMLParser. @interface MREntitiesConverter : NSObject { NSMutableString* resultString; NSString* xmlStr; NSData *data; NSXMLParser* xmlParser; } @property (nonatomic, retain) NSMutableString* resultString; - (NSString*)convertEntitiesInString:(NSString*)s; @end And this is the implementation: @implementation MREntitiesConverter @synthesize resultString; - (id)init { if([super init]) { self.resultString = [NSMutableString string]; } return self; } - (NSString*)convertEntitiesInString:(NSString*)s { xmlStr = [NSString stringWithFormat:@"<data>%@</data>", s]; data = [xmlStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; xmlParser = [[NSXMLParser alloc] initWithData:data]; [xmlParser setDelegate:self]; [xmlParser parse]; return [resultString autorelease]; } - (void)dealloc { [data release]; //I want to release xmlParser here but it crashes the app [super dealloc]; } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)s { [self.resultString appendString:s]; } @end If I release xmlParser in the dealloc method I am crashing my app but without releasing I am quite obviously leaking memory. I am new to Instruments and trying to get the hang of optimising this app. Any help you can offer on this particular issue will likely help me solve other memory issues in my app. Yours in frustrated anticipation: ) Oisin

    Read the article

  • Has NSXMLParser become more strict in iPhone SDK 3.x?

    - by D Carney
    I recently migrated an iPhone project from the 2.2.1 SDK to 3.1.x and, to my surprise, an XML feed that was (and still is with the published app) being parsed by the 2.2.1 NSXMLParser is now causing NSXMLParser to return errors. The XML document in question doesn't meet the W3C standard, but the 2.2.1 parser is able to handle this. I'm curious if anyone knows what changed and, more importantly, if there's a way to "relax" the 3.1.x parser. I don't have much control over the XML document, unfortunately, so I might have to get creative if I can't rely on the NSXMLParser to handle things as it did before.

    Read the article

  • Sending information back from delegate [iPhone]

    - by Andy
    I'm using NSXMLParser in my RootViewController.m file. NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:response_data]; [xmlParser setDelegate:self]; [xmlParser parse]; [xmlParser release]; I'm also implementing this method to add entries to a dictionary defined in RootViewController.m for later use: - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict However, I'd like to get more than one XML file and do different things when the file has finished; this sounds like I need to use external files as delegates. My question is: If I have the following implementation files (& their header files): RootViewController.m XMLDelegate1.m XMLDelegate2.m and set the ith NSXMLParser delegate to be XMLDelegatei.m, and get those files to return an NSDictionary that I can then add to the NSDictionary defined in RootViewController.m. I guess there are two methods of doing this: Use a method that I don't know about; or Use a better workflow I suspect it's 2, but hope it's 1. Thanks, Andy

    Read the article

1 2 3 4 5 6  | Next Page >