解析iOS sdk中的本地xml文件 [英] Parsing a local xml file in iOS sdk

查看:149
本文介绍了解析iOS sdk中的本地xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析按下UIButton时在我的资源文件夹中的本地xml文件。我知道如何从Web解析XML文件。现在我如何显示资源文件夹中的xml内容。

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.

如何解析本地XML文件?

How do I parse a local XML file?

推荐答案

我从您的标签中假设您正在使用NSXMLParser来解析XML。在这种情况下,你可以这样做:

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

这篇关于解析iOS sdk中的本地xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆