ok here is all the code i think you may need the parser.m
Code:
#import "BlogRssParser.h"
#import "BlogRss.h"
@implementation BlogRssParser
@synthesize currentItem = _currentItem;
@synthesize currentItemValue = _currentItemValue;
@synthesize rssItems = _rssItems;
@synthesize delegate = _delegate;
@synthesize retrieverQueue = _retrieverQueue;
- (id)init{
if(![super init]){
return nil;
}
_rssItems = [[NSMutableArray alloc]init];
return self;
}
- (NSOperationQueue *)retrieverQueue {
if(nil == _retrieverQueue) {
_retrieverQueue = [[NSOperationQueue alloc] init];
_retrieverQueue.maxConcurrentOperationCount = 1;
}
return _retrieverQueue;
}
- (void)startProcess{
SEL method = @selector(fetchAndParseRss);
[[self rssItems] removeAllObjects];
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self
selector:method
object:nil];
[self.retrieverQueue addOperation:op];
[op release];
}
-(BOOL)fetchAndParseRss{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//To suppress the leak in NSXMLParser
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.com/Data.xml"];
BOOL success = NO;
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:YES];
[parser setShouldReportNamespacePrefixes:YES];
[parser setShouldResolveExternalEntities:NO];
success = [parser parse];
[parser release];
[pool drain];
return success;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
if(nil != qualifiedName){
elementName = qualifiedName;
}
if ([elementName isEqualToString:@"item"]) {
self.currentItem = [[[BlogRss alloc]init]autorelease];
} else if([elementName isEqualToString:@"title"] ||
[elementName isEqualToString:@"description"] ||
[elementName isEqualToString:@"mediaUrl"] ||
[elementName isEqualToString:@"link"] ||
[elementName isEqualToString:@"mineralogy"] ||
[elementName isEqualToString:@"rarity"]) {
self.currentItemValue = [NSMutableString string];
} else {
self.currentItemValue = nil;
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if(nil != qName){
elementName = qName;
}
if([elementName isEqualToString:@"title"]){
self.currentItem.title = self.currentItemValue;
}else if([elementName isEqualToString:@"description"]){
self.currentItem.description = self.currentItemValue;
}else if([elementName isEqualToString:@"link"]){
self.currentItem.linkUrl = self.currentItemValue;
}else if([elementName isEqualToString:@"mediaUrl"]){
self.currentItem.mediaUrl = self.currentItemValue;
}else if([elementName isEqualToString:@"mineralogy"]){
self.currentItem.mineralogy = self.currentItemValue;
}else if([elementName isEqualToString:@"rarity"]){
self.currentItem.rarity = self.currentItemValue;
}else if([elementName isEqualToString:@"item"]){
[[self rssItems] addObject:self.currentItem];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(nil != self.currentItemValue){
[self.currentItemValue appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock{
//Not needed for now
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
if(parseError.code != NSXMLParserDelegateAbortedParseError) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[(id)[self delegate] performSelectorOnMainThread:@selector(processHasErrors)
withObject:nil
waitUntilDone:NO];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[(id)[self delegate] performSelectorOnMainThread:@selector(processCompleted)
withObject:nil
waitUntilDone:NO];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)dealloc{
self.currentItem = nil;
self.currentItemValue = nil;
self.delegate = nil;
[_rssItems release];
[super dealloc];
}
@end
and here is the object class that i would like to convert to a NSMutableArray
Code:
#import "BlogRss.h"
@implementation BlogRss
@synthesize title = _title;
@synthesize description = _description;
@synthesize linkUrl = _linkUrl;
@synthesize mineralogy = _mineralogy;
@synthesize rarity = _rarity;
@synthesize mediaUrl = _mediaUrl;
-(void)dealloc{
self.title = nil;
self.description = nil;
self.linkUrl = nil;
self.mineralogy = nil;
self.rarity = nil;
self.mediaUrl = nil;
[super dealloc];
}
@end
now what i would like to do is to search the objects for the relevant information using a UISearchBar and then populate a search results from this information and display this on the screen, but i've not had any luck in doing it this way so i was hoping that i may be able to get some help on how to populate the NSMutableArray from the contents of this class that is parsed from the xml and then search this array which may be an easier option as all the tutorials i can find only deal with searching an array.
if you need any more information then please ask and i'll do my best to post it.
Thanks
Brad
the link in the first posting will give you the code i was trying to use for the searchbar.