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 05-26-2011, 03:34 PM   #1 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Lightbulb XML parsing done, load from URL.

Hello guys!
Okay, so I finally managed to get my little XML parsing script to work! Fantastic! But I ain't satisfied.. not yet!
I've Googled around a bit, trying to find a thread that could teach me how to load my XML file from a specified URL adress - but without luck.
So now I'm a bit lost.
Do any of you have any luck loading XML data from a URL adress?

Thanks for your help!

Rail.
__________________

railion is offline   Reply With Quote
Old 05-26-2011, 04:01 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

just download the xml with NSURLConnection or ASIHTTPRequest, and then use stringResponde as xml.......

see section 4, there are some examples: http://www.iphonedevsdk.com/forum/ip...rvice-how.html
__________________
dany_dev is offline   Reply With Quote
Old 05-26-2011, 04:44 PM   #3 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
just download the xml with NSURLConnection or ASIHTTPRequest, and then use stringResponde as xml.......

see section 4, there are some examples: http://www.iphonedevsdk.com/forum/ip...rvice-how.html
My problem is more; how do I combine the XML parser and the NSURLCon.?
I think I'm getting this wrong
__________________

railion is offline   Reply With Quote
Old 05-26-2011, 04:55 PM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

1. Download XML file using NSURL Connection or ASIHTTP
2. On Download Complete, create xml parser and parse as normal
3. Everything else is the same
smithdale87 is offline   Reply With Quote
Old 05-26-2011, 06:58 PM   #5 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
1. Download XML file using NSURL Connection or ASIHTTP
2. On Download Complete, create xml parser and parse as normal
3. Everything else is the same
At this time, to locate my XML file (local in my project) I'm using:
Code:
NSString * path = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"xml"];
Just to be sure I get this right. The only thing I've to do is to point my path to a URL using the URLConnection?
__________________

railion is offline   Reply With Quote
Old 05-27-2011, 02:30 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by railion View Post
At this time, to locate my XML file (local in my project) I'm using:
Code:
NSString * path = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"xml"];
Just to be sure I get this right. The only thing I've to do is to point my path to a URL using the URLConnection?
can you open the link posted above and read code in section 4 or is too effort for you?

You just need to download the file and use the stringResponse (that will be the xml).


you could also do that
Code:
NSString *responseString = [[NSString alloc] initWithContentsOfURL:yourURL encoding:anEncoding error:nil];
//use responseString
[responseString  release];
but it is a synchronous request, so used on main thread freeze the UI during download....
__________________

Last edited by dany_dev; 05-27-2011 at 02:33 AM.
dany_dev is offline   Reply With Quote
Old 05-27-2011, 09:51 AM   #7 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
can you open the link posted above and read code in section 4 or is too effort for you?

You just need to download the file and use the stringResponse (that will be the xml).


you could also do that
Code:
NSString *responseString = [[NSString alloc] initWithContentsOfURL:yourURL encoding:anEncoding error:nil];
//use responseString
[responseString  release];
but it is a synchronous request, so used on main thread freeze the UI during download....
dany_dev: I've taken a look at your post and it looks great - I'm also starting to figure it out, I'm just a little bit slow in learning, ehh Sorry!
Anyway, I'm just having a little problem putting the bricks in the wall together, but I guess I'll figure it out sooner or later.
I really appreciate the help you're giving me - a huge thanks for that
__________________

railion is offline   Reply With Quote
Old 05-27-2011, 12:53 PM   #8 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Default

Okay, a little update.
I think I'm getting closer Using a little different way though.

Code:
   
NSString *filePath = @"URL";
NSURL *url=[[NSURL alloc] initWithString:filePath];
NSString *fileContent = [[NSString alloc] dataWithContentsOfFile:url]; NSXMLParser* parser = [[NSXMLParser alloc] initWithData:fileContent];
[parser setDelegate:self];
[parser parse];
[parser release];
[super viewDidLoad];
Still not working 100%.
__________________

railion is offline   Reply With Quote
Old 05-27-2011, 01:04 PM   #9 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

there are many weird things on your code


1-this line don't make sense for 2 reason: NSString don't have a method called "dataWithContentsOfFile". Second reason, also supposing that this method exist, you are using alloc and then a method that return an autoreleased object, don't make sense, should be [[NSString alloc] initWithData:aDataObject];
Quote:
NSString *fileContent = [[NSString alloc] dataWithContentsOfFile:url];

2-Why you are using initWithData passing a string? if you want to use initWithData: you need to pass a NSData*, fileContent is a NSString*
Quote:
NSXMLParser* parser = [[NSXMLParser alloc] initWithData:fileContent];
3-I advice you to use a delegate for NSXMLParser that is not self, to avoid too confusion on your view controller (I assume that self is your view controller)



The right code should be:
Code:
NSString *urlString = @"insert your url";
NSURL *url=[[NSURL alloc] initWithString:urlString];
NSXMLParser* parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser parse];
[parser release];
__________________

Last edited by dany_dev; 05-27-2011 at 01:21 PM.
dany_dev is offline   Reply With Quote
Old 05-27-2011, 01:06 PM   #10 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
there are many weird things on your code

Code:
NSString *urlString = @"insert your url";
NSURL *url=[[NSURL alloc] initWithString:urlString];
NSXMLParser* parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser parse];
[parser release];
FYI, the I removed the URL because I didn't wanted to share it with the whole internet :-)
Anyway, thanks for a quick answer, I'll test it right away.
__________________

railion is offline   Reply With Quote
Old 05-27-2011, 01:19 PM   #11 (permalink)
Registered Member
 
railion's Avatar
 
Join Date: Jan 2011
Posts: 118
railion is on a distinguished road
Default

Argh, SIGABRT and this line marked with green:
Code:
int retVal = UIApplicationMain(argc, argv, nil, nil);
I think I've taking on a too big project. I should read a bit more, before trying to make this.

***UPDATE***
I made a clean start; trying all over and apparently it works now!
Again, dany_dev, thank you so much for your patience and your help I've bookmarked your link, and I can tell I'm going to do some reading now
Have a nice day, there.
Cheers from Denmark!
__________________


Last edited by railion; 05-27-2011 at 01:25 PM.
railion is offline   Reply With Quote
Old 05-27-2011, 01:19 PM   #12 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by railion View Post
FYI, the I removed the URL because I didn't wanted to share it with the whole internet :-)
Anyway, thanks for a quick answer, I'll test it right away.
yes i know, but as you see in my post, is not the url the problem
__________________
dany_dev 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: 342
6 members and 336 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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