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 01-11-2011, 07:49 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
brush51 is on a distinguished road
Default From CoreData to XML Export

Hey folks,

i have some Data in my TableView(saved and loaded with coreData and sqlite). Now i want to export this data as an *.xml file.

How can i do that? Links and tips for me?


Thanks,
brush51
brush51 is offline   Reply With Quote
Old 01-11-2011, 07:57 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Fetch the object, via NSFetchRequest.
Create a NSMutableString, loop threw the items in the array create with the fetchRequest.
Append each item as needed to the MutableString, with the XML format you want,

Then you have your XML.
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.
TUX2K is offline   Reply With Quote
Old 01-11-2011, 09:42 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
brush51 is on a distinguished road
Default

Quote:
Originally Posted by TUX2K View Post
Fetch the object, via NSFetchRequest.
Create a NSMutableString, loop threw the items in the array create with the fetchRequest.
Append each item as needed to the MutableString, with the XML format you want,

Then you have your XML.
Thanks for your answer,

but i dont understand the "Fetch the object, via NSFetchRequest.
Create a NSMutableString, loop threw the items in the array create with the fetchRequest"
part.

Like this? :
Code:
NSFetchRequest *fr = [[NSFetchRequest alloc] init];
		[fr valueForKey:@"barCode"];
brush51 is offline   Reply With Quote
Old 01-11-2011, 09:47 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Read this: Loading…
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.
TUX2K is offline   Reply With Quote
Old 01-12-2011, 02:34 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
brush51 is on a distinguished road
Default

Quote:
Originally Posted by TUX2K View Post
Read this: Loading…
Ah ok i understand. Now i do this:

Code:
	NSManagedObjectContext *moc = [self managedObjectContext];
	NSFetchRequest *req = [[NSFetchRequest alloc] init];
	
	[req setEntity:[NSEntityDescription entityForName:@"Event" inManagedObjectContext:moc]];
	[req setIncludesPropertyValues:NO];
	
	NSError *error;
	
	NSArray *cars = [moc executeFetchRequest:req error:&error];
	[all release];
	
	for (NSManagedObject *Event in codes) {
		NSLog(@"look at that: ----> %@", Event);
		NSLog(@"whats this? : ------------> %@", codes);		
	}
I dont know how to get only the property.

Last edited by brush51; 01-12-2011 at 02:45 AM. Reason: added one line of code, the second NSLog
brush51 is offline   Reply With Quote
Old 01-12-2011, 02:45 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Code:
	NSManagedObjectContext *moc = [self managedObjectContext];
	NSFetchRequest *req = [[NSFetchRequest alloc] init];
	
	[req setEntity:[NSEntityDescription entityForName:@"Event" inManagedObjectContext:moc]];
	[req setIncludesPropertyValues:NO];
	
	NSError *error;
	
	NSArray *cars = [moc executeFetchRequest:req error:&error];
	[all release];
	
	for (Event *event in cars) {
               //Now you can get at all the properties of the class type event.

		NSLog(@"look at that: ----> %@", event);
		
	}
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.
TUX2K is offline   Reply With Quote
Old 01-12-2011, 03:16 AM   #7 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
brush51 is on a distinguished road
Default

I know but i want just the data from ONE property, named barCode.

How to do that?
brush51 is offline   Reply With Quote
Old 01-12-2011, 03:27 AM   #8 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

try this:
Code:
   NSMutableString *xmlString = [NSMutableString string];
   [xmlString appendString:@"<?xml version=\"1.0\" ?>\n"];
   [xmlString appendString:@"<BarCodeList>\n"];
   
    for (Event *event in cars) {
       [xmlString appendFormat:@"<BarCode>%@</BarCode>\n", event.barCode];
   }
   [xmlString appendString:@"</BarCodeList>"];

  NSLog(@"%@", xmlString);
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.
TUX2K is offline   Reply With Quote
Old 01-12-2011, 03:53 AM   #9 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
brush51 is on a distinguished road
Default

Quote:
Originally Posted by TUX2K View Post
try this:
Code:
   NSMutableString *xmlString = [NSMutableString string];
   [xmlString appendString:@"<?xml version=\"1.0\" ?>\n"];
   [xmlString appendString:@"<BarCodeList>\n"];
   
    for (Event *event in cars) {
       [xmlString appendFormat:@"<BarCode>%@</BarCode>\n", event.barCode];
   }
   [xmlString appendString:@"</BarCodeList>"];

  NSLog(@"%@", xmlString);
Thanks for sharing this code, i have included the Event class and defined es property event. But doesnt, work, i get (null).

Maybe the datas are not saved persistently??

When i do in case of event.barCode this:
Code:
[[managedObject valueForKey:@"barCode"] description]]
i get a few times the same code. For example i have 5 rows in the tableview, then i get 5 times the last row.
brush51 is offline   Reply With Quote
Reply

Bookmarks

Tags
coredata, export, 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: 360
9 members and 351 guests
7twenty7, blueorb, iAppDeveloper, iGamesDev, Mah6447, Morrisone, mottdog, sacha1996, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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