开发者

parsing a local xml file without using tableview controller

开发者 https://www.devze.com 2023-02-07 18:21 出处:网络
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

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"];
0

精彩评论

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