Re: Problem with nested tags in xml
Re: Problem with nested tags in xml
- Subject: Re: Problem with nested tags in xml
- From: "Stephen J. Butler" <email@hidden>
- Date: Wed, 12 Nov 2008 15:48:45 -0600
On Wed, Nov 12, 2008 at 3:41 PM, Ariel Rodriguez
<email@hidden> wrote:
> I'm playing with a REST implementation. Basically, i am following this
> tutorial:
> http://developer.apple.com/webapps/articles/creatingrestfulclients.html
> And, as you can see, the xml produced by the app is this:
> <?xml version="1.0" encoding="UTF-8"?> <CountryData> <country> <id>37</id>
> <country>Canada</country> <gdp>1274000000000</gdp> <iso_code>ca</iso_code>
> </country> </CountryData>
> Where each country has a country tag (the name). My question is how to parse
> an xml where there are nested tags with the very same name.
> I've tried to catch the country tag on
> parser:didEndElement:namespaceURI:qualifiedName: with an
> if([elementName isEqualToString:@"country"]) {}
> but this catch the parent and nested country tag. There is way to know the
> difference?
This is a classic example of where to use a finite state machine:
<http://en.wikipedia.org/wiki/Finite_state_machine>
Basically, you have an initial state and then an "inside country"
state. Then inside your
parser:didEndElement:namespaceURI:qualifiedName: you behave
differently based on the current state.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden