Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-10-2012, 03:28 AM   #1 (permalink)
Registered Member
 
joeallenpro's Avatar
 
Join Date: Dec 2009
Location: Essex, UK
Age: 19
Posts: 70
joeallenpro is on a distinguished road
Smile Gram one piece of data from XML

Hi guys

I need a quick lesson on grabbing data from XML...

I need to get the XML from a URL e.g: http://www.website.com/pathtoxml/?city=xxxxxxxx

here's an example of the XML:
Code:
<current_conditions>
<condition data="Clear"/>
<temp_f data="54"/>
<temp_c data="12"/>
<humidity data="Humidity: 77%"/>
<icon data="sunny.gif"/>
<wind_condition data="Wind: S at 6 mph"/>
</current_conditions>
<forecast_conditions>
<day_of_week data="Thu"/>
<low data="43"/>
<high data="70"/>
<icon data="sunny.gif"/>
<condition data="Clear"/>
</forecast_conditions>
<forecast_conditions>
<day_of_week data="Fri"/>
<low data="46"/>
<high data="63"/>
<icon data="chance_of_rain.gif"/>
<condition data="Chance of Rain"/>
</forecast_conditions>
Whats the easiest way to grab the "temp_c" from inside <current_conditions>


Thanks guys!
__________________
Visit AppStore

"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
joeallenpro is offline   Reply With Quote
Old 02-11-2012, 12:01 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: London/Peterborough
Posts: 562
QuantumDoja is on a distinguished road
Default

Some code I had to hand

Code:
@implementation DoSomething

-(void)ReadXMLAsString:(NSString*)xmlAsString
{
	
	
	NSData *data = [xmlAsString dataUsingEncoding:NSUTF8StringEncoding];
	NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
	[parser setDelegate:self];
	[parser parse];
	NSError *err = [parser parserError];
    
    if (err != nil)
    {
       NSLog([err localizedDescription]);

    }
    
    [parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
	if (qName)
	{
		elementName = qName;
	}
	
	if ([elementName isEqualToString:@"temp_c"])
	{
		m_someData = [[attributeDict valueForKey:@"data"] intValue];
	}
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{    
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
    m_contents = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
}

@end
QuantumDoja is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
12 members and 373 guests
chiataytuday, chits12345, ChrisYates, fiftysixty, fredidf, gmarro, KennyChong, kilobytedump, Leslie80, Meoz, ryantcb, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:28 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0