Hi everyone,
I'm a long-standing web developer and have recently switched to iPhone development. I am by no means a guru but I know my way around Objective-C.
I am currently working on a project which involves parsing XML. I have created a simple RSS reading application in the past, but my current project is giving me a few headaches. While the project is primarily going to be used by me personally, I want to plan the data model carefully so that in the future I could expand on it with an aim to producing a commercial release.
Effectively, I am developing an application which can parse an XML file representing, for example, study notes. Such a file would resemble the following:
Code:
<subject>
<title>Dogs</title>
<topic>
<title>Yorkshire Terriers</title>
<section>
<title>What is a Yorkshire Terrier?</title>
<text>A Yorkshire terrier is a breed of dog.</text>
<text>I like dogs, they're nice.</text>
<image>
<path>file.jpg</path>
<title>An image</title>
<caption>This is the caption</caption>
</image>
<graph>
<axes>0-10,0-10</axes>
<point>0,0</point>
<point>10,10</point>
</graph>
<subsection>
<title>Training Yorkshire Terriers</title>
<text>Yorkshire terriers are easy to train.</text>
<blist>
<item>This is the first item in a bulleted list.</item>
<item>This is the second item in a bulleted list.</item>
</blist>
<nlist>
<item>This is the first item in a numbered list.</item>
<item>This is the second item in a numbered list.</item>
</nlist>
</subsection>
</section>
</topic>
</subject>
The problem is that within a single 'section' or 'subsection' tag, I would like the rest of the data to be displayed in any order. While the 'title' tag is required, any number of 'text' tags (which would approximately equate to paragraphs), 'image' tags, graphs and lists could be displayed. For example, some sections will not contain any text, only images. Some sections will contain four paragraphs of text, others ten paragraphs etc..
My initial thoughts were to create a 'section' class (subject of NSObject), and parse the XML and create all the child objects on the fly (UILabels, UIImages etc.). Is this a viable approach? Or should I be doing something else entirely?
I am aware that this data could be very easily be recoded as HTML and displayed in a UIWebView, but I would like to avoid this as much as possible, since down the line I would like to add user interaction to individual objects, and I fear that lumping everything together within a web view would prevent me from doing so.
Sorry for such a long post!
Clovis