hmthur
hmthur

Reputation: 2565

NSXMLParser iPhone

When exactly does the delegate method in iPhone SDK gets called parser:didEndElement:...

Even though it says it gets called whenever NSXMLParser reaches the end of an element

Say we have an XML; 1 2 3

I am a bit unclear what exactly does "end of an element" mean ? Does it mean at the end of every element in the XML..So in the above example, will these method be called 4 times (once for and 3 times for the )

Also is these the main delegate method where majority of parsing takes place and not the other 2 methods; parser:(NSXMLParser *)parser didStartElement parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

Thank you.

Upvotes: 2

Views: 358

Answers (1)

Kevin Sylvestre
Kevin Sylvestre

Reputation: 38012

It gets called when it finishes parsing an element (that is it reaches a closing tag). For example, given the following XML:

<person>
  <name>Kevin</name>
</person>

It will be called when the parser reaches </name> and </person>.

Typically you are required to use a combination of the methods and no main delegate method exists. Usually you will start construction of an object on didStartElement, modify the data on foundCharacters and finalize or setup complex data structures in didFinishElement. The documentation is fairly clear for this.

Upvotes: 5

Related Questions