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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 03-09-2010, 07:37 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
Question Help with xml web service

Hello Friends,

I'm learning implementing web-services for iPhone.

Anyone please help me out to get data from following Webservice URL:

Request (HTTP GET)
Code:
http://api.stlouisfed.org/fred/category?category_id=125&api_key=78da607fc8224651eca5653e65a4be5e
Response:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<categories>
<category id="125" name="Trade Balance" parent_id="13"/>
</categories>
I want to display category-name from the response in a UILabel.

Thanks.
imsatasia is offline   Reply With Quote
Old 03-09-2010, 11:13 PM   #2 (permalink)
Will Work for Food!
 
itzdark's Avatar
 
Join Date: Apr 2009
Posts: 579
Send a message via AIM to itzdark Send a message via MSN to itzdark
Default

NSXMLParser

codesofa Make NSXMLParser your friend..
__________________

Check out my apps

Developers, check out study buddy. I use it everytime I code. It's great for those late night coding sessions.
Unofficial Ad Hoc Distribution Guide || Join my cooperative ad hoc testing group
iSoothe Promotional Video
Contact Me
itzdark is offline   Reply With Quote
Old 03-10-2010, 01:23 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
Default

Quote:
Originally Posted by itzdark View Post
Hi itzdark,

Thanks for link.

I'm new to Web services.

Will you please help me to write following methods for my demo web service.

Code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
Thanks again.
imsatasia is offline   Reply With Quote
Old 03-10-2010, 03:09 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
Default

This is How I have written my code:

Code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
	currentElement = [[elementName copy] autorelease];
	NSLog(currentElement);
	if ([elementName isEqualToString:@"category"]) 
	{
		lbl1.text = [attributeDict valueForKey:@"name"];
		NSLog([attributeDict valueForKey:@"name"]);

		hello = FALSE;
	}
}
	
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
		if (hello) {
			[currnetCategory appendString:string];
		}
}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
	currentElement = [[elementName copy] autorelease];
	NSLog(currentElement);
	if ([elementName isEqualToString:@"categories"])
	{
		return;
	}
	
	else if([elementName isEqualToString:@"category"]) 
		{
			NSLog(lbl1.text);
			hello = FALSE;
		
		}
}

it is giving me the correct value for NSLog([attributeDict valueForKey:@"name"]); in gdb.

- But at the end of xml file it was giving me error "EXC_BAD_ACCESS".
imsatasia is offline   Reply With Quote
Old 03-10-2010, 04:26 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
Default

Here is my Log:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<categories>
<category id="125" name="Trade Balance" parent_id="13"/>
</categories>
2010-03-10 13:25:12.788 testxml[11864:207] categories
2010-03-10 13:25:12.789 testxml[11864:207] category
2010-03-10 13:25:12.789 testxml[11864:207] Trade Balance
2010-03-10 13:25:12.790 testxml[11864:207] category
2010-03-10 13:25:12.790 testxml[11864:207] Trade Balance
2010-03-10 13:25:12.791 testxml[11864:207] categories
then the app was terminated.

Thanks
imsatasia is offline   Reply With Quote
Old 03-10-2010, 04:45 PM   #6 (permalink)
Will Work for Food!
 
itzdark's Avatar
 
Join Date: Apr 2009
Posts: 579
Send a message via AIM to itzdark Send a message via MSN to itzdark
Default

Run it again, when it crashes click the little spraypaint can button next to the gdb button this will show you the line it crashed it on. This well help point you in the right direction.

EXC_BAD_ACCESS indicates you tried to use a variable that has been released or wasn't initialized properly
__________________

Check out my apps

Developers, check out study buddy. I use it everytime I code. It's great for those late night coding sessions.
Unofficial Ad Hoc Distribution Guide || Join my cooperative ad hoc testing group
iSoothe Promotional Video
Contact Me

Last edited by itzdark; 03-10-2010 at 04:48 PM.
itzdark is offline   Reply With Quote
Old 03-10-2010, 04:57 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
Default

Quote:
Originally Posted by itzdark View Post
Run it again, when it crashes click the little spraypaint can button next to the gdb button this will show you the line it crashed it on. This well help point you in the right direction.

EXC_BAD_ACCESS indicates you tried to use a variable that has been released or wasn't initialized properly

It was stopping at the end of this method:

Code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
	currentElement = [[elementName copy] autorelease];
	NSLog(currentElement);
	if ([elementName isEqualToString:@"categories"])
	{
		return;
	}
	
	else if([elementName isEqualToString:@"category"]) 
		{
			NSLog(lbl1.text);
			hello = FALSE;
		
		}
}

Thanks.
imsatasia is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, webservice

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: 257
20 members and 237 guests
ADY, Alsahir, beleg_1998, Dani77, e2applets, iph_s, JamesCahall, JasonR, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, Rudy, smithdale87, timle8n1, Touchmint, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,756
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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