01-11-2011, 07:49 AM
#1 (permalink )
Registered Member
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
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
01-11-2011, 07:57 AM
#2 (permalink )
Registered Member
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
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 .
01-11-2011, 09:42 AM
#3 (permalink )
Registered Member
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
Quote:
Originally Posted by
TUX2K
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"];
01-11-2011, 09:47 AM
#4 (permalink )
Registered Member
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
__________________
If my answer helped you, you might want to help me.
Make a
donation via PayPal .
01-12-2011, 02:34 AM
#5 (permalink )
Registered Member
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
Quote:
Originally Posted by
TUX2K
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
01-12-2011, 02:45 AM
#6 (permalink )
Registered Member
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
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 .
01-12-2011, 03:16 AM
#7 (permalink )
Registered Member
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
I know but i want just the data from ONE property, named barCode.
How to do that?
01-12-2011, 03:27 AM
#8 (permalink )
Registered Member
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
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 .
01-12-2011, 03:53 AM
#9 (permalink )
Registered Member
Join Date: Dec 2010
Location: Germany, Frankfurt
Posts: 30
Quote:
Originally Posted by
TUX2K
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.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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