如何将XML文件加载到iPhone项目中 [英] How To load XML file into iPhone project

查看:215
本文介绍了如何将XML文件加载到iPhone项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要为iPhone加载的XML文档,是否需要先将其转换为plist?如果可以,怎么办?

I have an XML documment that I want to load for the iPhone, do I need to convert it to a plist first ? if so how ?

该xml文档具有以下代码(适用于1章)

The xml document has the following code ( for 1 chapter)

<toolTipsBook>
−  <chapter index="1" name="Chapter Name">
<line index="1" text="line text here"/>
<line index="2" text=" line text here "/>
<line index="3" text=" line text here "/>
<line index="4" text=" line text here "/>
<line index="5" text=" line text here "/>
<line index="6" text=" line text here "/>
<line index="7" text=" line text here "/>
</chapter>

如何告诉xcode显示第1章第1行,然后在其下面留出空间以直接在第1章第1行的注释(单独的xml文档).

How can I tell xcode to display chapter 1 line 1 and then leave space under that for my comment ( a seperate xml document) for chapter l line 1 directly under it.

这个想法是,我将对要加载的数据中的所有章节都拥有此控件.

The idea is that I'll have this control for all the chapters in the data I'm loading.

如果您有空的话,如果您能提供一些示例以说明您的意思,我将不胜感激.

If you have a little time I'd really appreciate it if you could give some sample could to please show what you mean.

谢谢大家,

推荐答案

您可以将XML文件添加到应用程序的资源中.

您可以通过将其拖动到Xcode的资源目录中,然后在弹出窗口中选择将文件复制到项目中来实现.

You do that by dragging to resources directory in Xcode, and in popup select copy file to project.

运行应用程序时,您可以通过使用文件名来打开文件,读取XML,使用NSXMLParser解析文件并提取所需的数据.无需转换为plist.

When your application run you open the file by referring to it by it's name, read in the XML, parse it with NSXMLParser and extract required data. No need to convert to plist.

这假设xml数据是静态的,并且您不缩进来更新和保存它.

This assumes that the xml data is static and you don't indent to update and save it.

这篇关于如何将XML文件加载到iPhone项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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