Parsing a local xml file in iOS sdk
Asked Answered
A

1

24

I need to parse a local xml file which is in my 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?

Aldos answered 7/2, 2011 at 5:47 Comment(0)
D
43

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
Desensitize answered 7/2, 2011 at 6:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.