views:

35

answers:

2

I already know how to parse XML Elements that contain content (<this> Content </this> in Objective C but I am currently using a web service that returns the content I need in between two closed elements (<begin-paragraph/> The content I need <end-paragraph/>) I have been looking online for any examples of anyone else doing this, but I could not find anything. If anyone knows how to read between the two empty elements and would care to share, I would appreciate that very much.

A: 

I don't know what the DOM conformance on the iPhone is like, but the general procedure would be:

  1. Navigate to <begin-paragraph /> in your DOM.
  2. Get the next sibling of that node. That is the content you need. (Node::nextSibling property)
  3. If there are other elements in there that you want, keep collecting them by the same method, until you reach <end-paragraph />
Paul Butcher
+2  A: 

I have to say I regard that as an abuse of XML.

But I've checked and sadly it is well formed so NSXMLParser (which I assume is what you are using) should be able to cope with it.

You basically need to check which element you are in by handling the start element and end element events in your NSXMLParserDelegate. Then after receiving the –parser:didEndElement:namespaceURI:qualifiedName: message for begin-paragraph grab all the text you receive in -parser:foundCharacters: until you receive –parser:didStartElement:namespaceURI:qualifiedName:attributes: for end-paragraph

JeremyP
Thank you, this helped out a lot
Heheas