0

Let's say I have an XML-file looking like this:

<messages>
  <message id="1">
    <text>Hello</text>
    <text>How are you?</text>
    <from>Mr. Nice</from>
  </message>
  <message id="1">
    <text>Howdy</text>
    <text>What's up?</text>
    <from>Mrs. Nice</from>
  </message>
</messages>

How do I then populate a sectioned table like this:

HEADER 1 = Mr.Nice

TABLECELL 1.1 = Hello, TABLECELL 1.2 = How are you?

HEADER 2 = Mrs.Nice

TABLECELL 2.1 = Howdy, TABLECELL 2.2 = What's up?

Thanks in advance!

// Sebastian

  • Currently I'm using objectAtIndex:indexPath.row, but as the next section comes along the row will restart at 0, which I'm not certain how to fix. – osynligsebastian Jan 30 '12 at 17:23
  • Please update your question with details on how you have parsed your XML into array(s) to use as a datasource - it sounds like your problem is either in your data source methods or the way you have parsed the XML. Do you want one section per `message` element or to group all messages from the same person under one section? – jrturton Jan 30 '12 at 17:26

1 Answers1

0

To parse your xml into something useful to your app, say, by populating a collection of objects, you will need to start with NSXMLParser.

To understand how NSXMLParser applies to your situation, here is a fantastic tutorial describing how to use it with an XML file.

Jeremy
  • 8,902
  • 2
  • 36
  • 44
  • Well. I have everything set up and it's working, most of it. Though the second table has the same tablecell values as the first one. – osynligsebastian Jan 30 '12 at 16:57
  • See also this post regarding selecting the right parser for the job: http://stackoverflow.com/questions/4181690/choosing-the-right-ios-xml-parser. The "How To Choose The Best XML Parser for Your iPhone Project" link is excellent. – wmorrison365 Jan 30 '12 at 17:02
  • @Vin my apologies. I've updated my answer to fix the link. Thanks! – Jeremy Feb 02 '12 at 14:52