I need to know that i have a XML file, in my project I have some data in it. How can i display that data in TableView, Tutorials given on internet serve the purpose to display XML data that is through some URL, i just want to display from my local file in project.
Asked
Active
Viewed 361 times
4 Answers
0
I assume you are using Objective-C, am I correct?
Have you tried using NSXMLParser. I would assume you would be able to just use the contents of the file in your project and parse it with NSXMLParser.
You might want to have a look at this NSXMLParser example
-
yes i am using objective C, but i don't know the proper procedure to do that i need some code with explanation. – Ali Ashraf Jan 17 '12 at 06:15
0
NSString *xmlFilePath=[[NSBundle mainBundle] pathForResource:@"TesingSampleXml" ofType:@"xml"];
NSString *xmlString=[[NSString alloc]initWithContentsOfFile:xmlFilePath];
NSData* xmlData=[xmlString dataUsingEncoding:NSUTF8StringEncoding];
xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
[xmlParser setDelegate:self];
[xmlParser parse];
Now Parse the data using the delegates of the NSXMLParserDelegates and then reload the tableview.

Anil Kothari
- 7,653
- 4
- 20
- 25
-
i do not understand how the data would come here, i am using pathForResource and i gave the path of my xml file there but still its not working ... kindly help me in giving complete understanding – Ali Ashraf Jan 17 '12 at 06:17
-
try to NSLog(@"%@",xmlString); it will show your complete xml File – Anil Kothari Jan 17 '12 at 06:30
-
After that i have converted it into NSData type and loaded the NSXMLParser instance with it. – Anil Kothari Jan 17 '12 at 06:31
-
-
NSString *xmlFilePath=[[NSBundle mainBundle]pathForResource:@"/Users/apple/Downloads/XML/Books.xml" ofType:@"xml"]; NSLog(@"file path is %@",xmlFilePath); NSString *xmlString=[[NSStringalloc]initWithContentsOfFile:xmlFilePath]; NSLog(@"file path is %@",xmlString); – Ali Ashraf Jan 17 '12 at 07:09
-
the code u sent is ok this is my modified code have a look - (void)applicationDidFinishLaunching:(UIApplication *)application { // NSString *xmlFilePath=[[NSBundle mainBundle] pathForResource:@"/Users/apple/Downloads/XML/Books.xml" ofType:@"xml"]; NSString *xmlString=[[NSString alloc]initWithContentsOfFile:xmlFilePath]; NSLog(@"file path is %@",xmlString); NSData* xmlData=[xmlString dataUsingEncoding:NSUTF8StringEncoding]; XMLParser *xmlParser = [[XMLParser alloc] initXMLParser]; xmlParser = [[NSXMLParser alloc] initWithData:xmlData]; [xmlParser parse]; } – Ali Ashraf Jan 17 '12 at 07:14
-
drop the xml in resource folder then only give the filename inside the pathforresource – Anil Kothari Jan 17 '12 at 07:52
0
Best XML Parser tutorial
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project

Amit
- 1,795
- 1
- 17
- 20
0
To display data from xml file you need to parse the xml file. To parse file you can use any parser like - NSXMLParser, tbxml and so on
*I recommend TBXML * it is fast and light
-
but i don't know the proper procedure to do that i need some code with explanation. – Ali Ashraf Jan 17 '12 at 06:15