Does anyone have some idea how to parse the following xml using event-driven model NSXMLParser class?
<Node>
<name> Main </name>
<Node>
<name> Child 1 </name>
</Node>
<Node>
<name> Child 2 </name>
</Node>
</Node>
I want to collect all three names from this xml file, is it possible, or I have to change to Tree-based parsing?
This is a common problem with parsers like this one, of “type SAX”, where you have to manually keep track of the current depth of the XML tree you’re in. The problem, as always, is that loading the entire tree in a DOM structure in memory can be impossible, depending on the size of the data you want to manipulate.
The following code shows a class that does this job:
This is the implementation:
This is the result of running a command line tool that triggers the “start” method above: