Parsing an XML file stored in the Documents directory of an iPhone application
Asked Answered
D

1

7

NSXMLParser has three types of init.

-> init

-> initWith Data

-> initWithContents of URL


=> But my xml file is stored at Application's Document directory, so how to parse a file which is stored at "Doc Dir"

Thanks in advance.

Diego answered 24/8, 2009 at 19:57 Comment(0)
D
11

nsdata can be initialize with the contents of a file. Use the initWithContentsOfFile instance method with NSDAta and supply that to nsxmlparser's initWithData method:

NSString * filePath = [[NSBundle mainBundle] pathForResource:@"someFile"
                                                      ofType:@"xml"];
NSData * fileData = [NSData dataWithContentsOfFile:filePath];
NSXMLParser * parser = [NSXMLParser initWithData:fileData];
Dairy answered 24/8, 2009 at 20:4 Comment(2)
Thanks Sir, I completely forgot that. Thanks for helping me.Diego
You beat me to it, so I added my code to your answer. Please edit as you see fit. :)Melantha

© 2022 - 2024 — McMap. All rights reserved.