I am trying to select a random Bible verse from XML files I already have. I’d like to extract a random verse, display it then also display the verse number and book name.
I have several XML files so converting them to Plist might be a hassle and I am not sure if I use a dictionary that I can also extract the chapter number and book name.
The XML files look like this…
<bible translation="KJV">
<testament name="Old">
<book index="1" name="Genesis">
<chapter index="1">
<verse index="1" text="In the beginning God created the heaven and the earth."/>
<verse index="2" text="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."/>
<!-- THE REST OF THE XML HERE -->
</chapter>
</book>
</testament>
Any idea on how I can select a random verse in and then display the text, book name and chapter number?
A fairly simple solution would be to take your XML file and format it as a ‘Property List’ (plist) file – these can be handled easily in Objective-C. Essentially a ‘Property List’ is just an XML file so the effort in converting it should be minimal.
You can then fill an array or dictionary with the contents of your ‘plist’ file and simply generate a random number to use as the index to select an object from your array. There’s plenty of info around the web for how to handle plist files, a simple tutorial you can check out here