parsing a local xml file without using tableview controller
Dear all, I need parse a local xml file 开发者_如何转开发without using a navigation controller. And i studied all the documents. But still am confused.Can anyone explain me fully with one full sample example code.
or tell me how can i access/read the local xml file to display it in a uiwebview?
Parsing any kind of data and displaying it properly is a great way to boost your programming skills.
On the iPhone there are many options for parsing, but first you have to load your file:
NSString *filePath = [[NSBundle mainBundle]
pathForResource:@"MyFile" ofType:@"txt"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
// do something useful
}
Once you have that working, you can get to parsing the file. I love using Xpath, it makes finding the elements you need and storing/displaying/manipulating becomes dead easy. There are some great libraries and frameworks for using Xpath.
My personal favorite is XpathQuery.
By the sound of things, you're going to be reading a simple file and displaying things in a pretty normal fashion. The following will work:
#import "XpathQuery"
NSArray *queryResult = PerformXMLXPathQuery(myData, @"/aNode");
myTextField.text = [[queryResult objectAtIndex:0] objectForKey:@"nodeContent"];
精彩评论