开发者

Parsing a local xml file in iOS sdk

开发者 https://www.devze.com 2023-02-09 03:27 出处:网络
I need to parse a local xml file which is in m开发者_如何学Cy resource folder when a UIButton is pressed. I know how to parse an XML file from the web. Now how can i display the xml content which is i

I need to parse a local xml file which is in m开发者_如何学Cy resource folder when a UIButton is pressed. I know how to parse an XML file from the web. Now how can i display the xml content which is in my resource folder.

How do I parse a local XML file?


I assume from your tags that you're using NSXMLParser to parse the XML. In that case, you can do this:

NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"xml"];
NSData *xmlData = [NSData dataWithContentsOfFile:xmlPath];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
// do whatever you want with xmlParser
0

精彩评论

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