Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-01-2011, 06:34 AM   #1 (permalink)
Steven Curtis
 
Join Date: Jan 2011
Location: Bedfordshire, UK
Age: 28
Posts: 8
sdc121 is on a distinguished road
Send a message via MSN to sdc121 Send a message via Skype™ to sdc121
Default Receiving data from XML file and want save to SQLite

Hi People.

i am trying to setup a iPhone app that pulls XML file from the internet and then want it to save to a SQLite database. the coding i am using to parser the XML file is:

SQLViewAppDelegate.m
Code:
	NSURL *url = [[NSURL alloc] initWithString:@"http://www.180designlab.com/waxjambu/getupdates.xml"];
	NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	XMLParser *parser = [[XMLParser alloc] initXMLParser];
	[xmlParser setDelegate:parser];
	BOOL success = [xmlParser parse];
	NSLog(@"Info array has %d items", [infoGet count]);
	totalCount = [infoGet count];
	//[self save_Clicked];

	if(success)
		NSLog(@"No Errors");
	else 
		NSLog(@"Error Error Error");
XMLParser.m
Code:
-(XMLParser *)initXMLParser {
	[super init];
	appDelegate = (SQLViewAppDelegate *)[[UIApplication sharedApplication] delegate];

	return self;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
	if ([elementName isEqualToString:@"Updates"]) {
		appDelegate.infoGet = [[NSMutableArray alloc] init];
	}
	else if ([elementName isEqualToString:@"Update"]) {
		aInfo = [[XMLInfo alloc] init];
		aInfo.infoGetID = [[attributeDict objectForKey:@"id"] integerValue];

		
		//aGetInfo.info
		NSLog(@"Info ID Value: %i", aInfo.infoGetID);

	}

	NSLog(@"Processing Element: %@", elementName);

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
	currentElementValue = [[NSMutableString alloc] initWithString:string];
else 
	[currentElementValue appendString:string];
	//[self saveData];
	NSLog(@"Processing Value: %@", currentElementValue);
	NSLog(@"Processing ID: %d", aInfo.infoGetID);
	getInfo *infoObj = [[getInfo alloc] initWithPrimaryKey:0];
	infoObj.infoTitle = aInfo.title;
	infoObj.infoDescription = aInfo.description;
	infoObj.infoLink = aInfo.link;
//	[infoObj addInfo];
	
	//Add it to the coffee array.
//	[appDelegate.infoArray addObject:infoObj];		
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"Updates"])
	return;
	if ([elementName isEqualToString:@"Update"]) {
		[appDelegate.infoGet addObject:aInfo];
		
		[aInfo release];
		aInfo = nil;
	}
else
	[aInfo setValue:currentElementValue forKey:elementName];
	[currentElementValue release];
	currentElementValue = nil;
}
I can get the data in to a tableView but can not work out how to save them to SQLite file I have up.

I can load data to a tableView from the SQLite file fine as well.. I also now how add to SQLite when using a AddView when you enter data in two textfields. what ever I try it comes up saying out of memory. I know it be something simple but just cant fine or work this out.

hope someone can help me with this.

I look forward in hearing back from you
sdc121 is offline   Reply With Quote
Old 07-07-2011, 07:49 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 28
rafiq is on a distinguished road
Default

Hi,
Am also seeing for the same thing.If u have done an u guide me.
Thanks
rafiq is offline   Reply With Quote
Old 07-07-2011, 08:44 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

I save to Core Data at this point:
Code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"Updates"])
	return;
	if ([elementName isEqualToString:@"Update"]) {
		[appDelegate.infoGet addObject:aInfo];
		Save to the file here
		[aInfo release];
		aInfo = nil;
	}
else
	[aInfo setValue:currentElementValue forKey:elementName];
	[currentElementValue release];
	currentElementValue = nil;
}
It looks to me there as if you are adding something to an array? Is "infoGet" defined as an array in your app delegate?

Now you didnt mention anything about Core Data so ill assume that you are just saving to a normal SQLite file? As that is the case i cant help you too much as i have been focusing on Core Data, but ill show you what i have to save to that. As i said this is in the "didEndElement" method:
Code:
 else if ([elementName isEqualToString:@"item"]) {
NSManagedObject *newSalesInvoiceItem = [NSEntityDescription insertNewObjectForEntityForName:@"EntityName" inManagedObjectContext:newContext];
            
            [newSalesInvoiceItem setValue:aSalesInvoiceItems.iicIcId forKey:@"iicIcId"];
NSError *error;
        if (![managedObjectContext save:&error]) {
            
        }
So i am opening up the Managed object for my entity (in bold) - this i think you may be able to skip, instead having it as the reference to your SQLite file, i the set the value from the server (italics) to the key in the database. At the end of it all i exit with a save.

Its a little side tracked from what you are looking for but hopefully it will help put you on the right lines.
Meredi86 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, sqlite, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 364
18 members and 346 guests
Absentia, akphyo, apatsufas, BinHex, cpsclicker, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, teebee74, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:17 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0