user927187
user927187

Reputation: 33

Can an externally created XML file included in the plist of a project (in xcode)?

I have an external valid XML file. Can I simply save it in the Xcode project folder to make it available as a plist?

Upvotes: 0

Views: 784

Answers (1)

0x8badf00d
0x8badf00d

Reputation: 6401

Whether its plist or xml you can drag and drop in your XCode project resources folder (its common place where we save application resources like property list files, xml files,images). You can read file using:

NSString* path = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"plist"];
NSDictionary* tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSLog(@"Plist Contents: %@",tempDict);
[tempDict release]; 

If its an xml

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"xml"];
NSData* xmlData = [NSData dataWithContentsOfFile:filePath];
if(xmlData)
{
 NSString* xmlDataString = [[NSString alloc] initWithData:xmlData encoding:NSASCIIStringEncoding];
 NSLog(@"XML file Contents:%@",xmlDataString);
 [xmlDataString release];
}

If you are looking to parse XML using NSXMLParser you can give that file to NSXMLParser to load and parse. initWithContentsOfURL: method

Upvotes: 1

Related Questions