• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Noob question in regards to NSXMLParser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Noob question in regards to NSXMLParser


  • Subject: Re: Noob question in regards to NSXMLParser
  • From: "Hank Heijink (Mailinglists)" <email@hidden>
  • Date: Tue, 07 Jun 2011 10:13:51 -0400

Two ways that I've used:

1. Keep a boolean isInCurrentConditions that you set when you start the current_conditions element and reset when you end that element. Then every time you enter a condition element you check the boolean to see if you are where you need to be in the hierarchy. This works well enough if your hierarchy is not too complicated and you only need to know about a couple of elements. If it does get complicated, you'll end up tracking a dozen booleans, which I don't recommend.

2. The complicated case: keep a stack of element names. Every time you enter one, you push it, and every time you leave you pop it (it pays to check what you're popping, just in case). Then, whenever you encounter a condition element, you check the stack to see if you're at the right place in the hierarchy.

I'm sure there are other ways, but these have worked well for me.

Hope this helps,
Hank

On Jun 7, 2011, at 10:03 AM, Eric E. Dolecki wrote:

> I am fetching some XML weather from Google:
>
> <xml_api_reply version="1">
> <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0"
> section="0">
> <forecast_information>
> <city data="Framingham, MA"/>
> <postal_code data="01701"/>
> <latitude_e6 data=""/>
> <longitude_e6 data=""/>
> <forecast_date data="2011-06-07"/>
> <current_date_time data="2011-06-07 12:38:31 +0000"/>
> <unit_system data="US"/>
> </forecast_information>
> <current_conditions>
> <condition data="Sunny"/>
> <temp_f data="69"/>
> <temp_c data="21"/>
> <humidity data="Humidity: 66%"/>
> <icon data="/ig/images/weather/sunny.gif"/>
> <wind_condition data="Wind: NW at 3 mph"/>
> </current_conditions>
> <forecast_conditions>
> <day_of_week data="Tue"/>
> ...
>
> What I am really after is the current_conditions data. How can one specify
> WHERE in the XML to use the attributes from? A lot of the information is
> repeated in other nodes so I can't just check (if([elementName
> isEqualToString:@"condition"]){) , how can I check if the current element is
> within a specific tag? (In this case the parent is current_conditions)?
>
> Eric
> _______________________________________________
>
> 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
>

_______________________________________________

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

  • Follow-Ups:
    • Re: Noob question in regards to NSXMLParser
      • From: "Eric E. Dolecki" <email@hidden>
References: 
 >Noob question in regards to NSXMLParser (From: "Eric E. Dolecki" <email@hidden>)

  • Prev by Date: Noob question in regards to NSXMLParser
  • Next by Date: Re: Noob question in regards to NSXMLParser
  • Previous by thread: Noob question in regards to NSXMLParser
  • Next by thread: Re: Noob question in regards to NSXMLParser
  • Index(es):
    • Date
    • Thread