2011-06-01 56 views
0

我正在为iPhone编写一个圣经内存应用程序,我需要一些帮助来挑选UIWebView中显示的经文。从UIWebView中提取XML元素

我有一个读入UIWebView的xml文件,我需要能够告诉用户何时点击特定的诗句。下面是XML文件的样本:

<bible translation="KJV"> 
<testament name="Old"> 
    <book name="Genesis"> 
     <chapter number="1"> 
      <verse number="1">In the beginning God created the heaven and the earth.</verse> 
      <verse number="2">And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</verse> 
      <verse number="3">And God said, Let there be light: and there was light.</verse> 
      <verse number="4">And God saw the light, that it was good: and God divided the light from the darkness.</verse> 
      <verse number="5">And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</verse> 

在上面相对于代码,如果用户水龙头“一开始...”的程序需要知道(至少),用户只需点击一个“诗句“元素和它的”数字= 1“。

=================== EDITED ========================= =

这里是我提出的解决方案..类型。有点。 让我知道它听起来如何。

我仍然有读取XML文件的UIWebView。它也被格式化为捆绑中的CSS文件。由于UIWebViews注意到链接(hrefs)[感谢乔纳森]我可以在每个标记的诗句前面添加诗句数字(我知道它有点乏味,但我打算继续做它:)

这样, xml文件看起来像这样:

<bible translation="KJV"> 
<testament name="Old"> 
    <book name="Genesis"> 
     <chapter number="1"> 
      <n>1</n><verse number="1">In the beginning God created the heaven and the earth.</verse> 
      <n>2</n><verse number="2">And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</verse> 
      <n>3</n><verse number="3">And God said, Let there be light: and there was light.</verse> 
      <n>4</n><verse number="4">And God saw the light, that it was good: and God divided the light from the darkness.</verse> 
      <n>5</n><verse number="5">And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</verse> 
      <n>6</n><verse number="6">And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.</verse> 
      <n>7</n><verse number="7">And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so.</verse> 

我要么使用CSS来强制“N”标记作为链接或只是把“href”属性的元素来代替。 这样,当经节号码被发现之前,我可以通过自定义的方法来确定我在哪里(我在哪个诗句中)。 这里有一个帖子,我发现关于拦截的链接触发的UIWebView中: http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/

我希望这会工作,它的一个小广告hockish ..但计划往往开始的方式。 任何人都可以尝试这样的事情吗?

回答

0

的UIWebView的委托只回应链接(的HREF),所以这可能是一个问题。从理论上讲,你可以通过做一些命中检测来解决这个问题,但是这会更明智一点(再加上你晚上会睡得更好:D)来解析XML并将其加载到UITableView中,更易于维护和多用户友善。

+0

你知道...获得一些良好的睡眠时间很重要:) 除非我不知道如何调整它,否则UITableView可能在应用程序的外观和感觉上有点具有挑战性。这些经文经常会重叠并且位于同一行,并且每个经文都在自己的表格单元格中显示为块状。不过,我正在完成一个xml解析器的过程,所以如果有一种方法可以将UIWebView的连续外观变成UITableView,我很乐于接受。 但我并不知道UIWebViews注意到了链接。这是一件好事,因为我也有这个计划。我会在一秒之内发布我的想法。 – 2011-06-02 00:59:58

+0

使用NSXMLParser来解析XML。了解如何首先解析XML,然后尝试弄清楚如何使用它与UITableView。你不能试着去学习如何做一些事情,同时试图把它解决成你正在试图解决的问题。 – 2011-06-02 06:09:54

+0

你说得对。我开始使用NSXMLParser将xml解析器放在一起,用Testaments-> Books [] - > Chapters [] - > Verses []构建一个圣经对象。当我想要自己显示一个经文列表时,这对UITableView来说非常方便。 但是,我想使用UIWebView来显示圣经本身,如下所示: http://www.ebooktechie。com/wp-content/uploads/2008/11/iphonebibleapp.jpg 通过这种方式,诗歌#将链接到即将到来的诗节的信息,其余的文本将是常规的“诗歌”元素。 – 2011-06-02 13:02:15