I have a file:
<xml>
<component>something
<system>somethingDeeper
<value>somethingDeepest</value>
</system>
</component>
<component>somethinfDifferent
<value>somethingDifferentDeeper</value>
</component>
<value>somethingNew</value>
</xml>
So I want to distinguish what is inside another tag (ex. <system>) what is not. How to do this with NSXMLParser? I currently use BOOL ivar’s but this is a lot of tags and this is not as elegant as I want it to be. I know that NSXMLParser is a SAX parser and I understand that.
In above example I will be enter to didEndElement method three times with:
elementName equal value Is there a more elegant way to distinguish what entry was from <component> tag above what not?
You could keep an array of tag names you are currently within
Each time you enter a new element you add it to this array. Each time you leave you remove it again. i.e.
and
So, when you are parsing
somethingDeepestyour tagNameStack array would beYou can use this stack to decide where you are in the xml i.e.