开发者

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

I have an external valid XML file. Can I simp开发者_C百科ly save it in the Xcode project folder to make it available as a plist?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜