Im new to IOS from Android and am wondering how to parse xml with several tags into a listview. and once that has been parsed have the click action launch a detail webview with the url from the link tag.Here is one of the lists. a rough guideline or a tutorial would be amazing. http://graffiti.hostoi.com/00Graffiti00/lists/arts.xml
it looks like this in android
Check this link for parse xml parse
NSString *url=#"http://www.lancers.jp/work/search/.rss";
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
NSDictionary *dict=[XMLReader dictionaryForXMLData:data error:nil];
Check this link also
Demo code of XML
Related
All I want is to change every time the NSString townLocation.
Because I take data from an API and I don't want to create different API for different location. Also I know that the "+" that I put on the link is not correct and there is not such think in Objective C but I want to make you understand what I want.
NSString*townLocation;
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://api.openweathermap.org/data/2.5/find?q="+townLocation+"&units=metric"]];
How I must do it ? Im sure you understand that I'm new at Objective C
Thank you
You only need to look into the most basic NSString documentation to find a method that will do that, stringWithFormat:.
NSString *urlString = [NSString stringWithFormat:#"http://api.openweathermap.org/data/2.5/find?q=%#&units=metric", townLocation];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
If you're new at Objective-C, a good place to find information like this is to simply search the internet or the iOS Developer Library for the class in question (in this case, NSString) to find a myriad of resources at your disposal. Another doc to check would be Formatting String Objects, which is linked in the stringWithFormat: section of the iOS Developer Library, to find more info about formatting strings.
I'm trying to build an iOS app like Pocket or Instapaper for practice. So, I need to fetch data from a url and strip the HTML of of it. I created the code below to do this.
NSURL *url = [NSURL URLWithString:self.link];
NSString *webData= [NSString stringWithContentsOfURL:url];
NSLog(#"webData is: %#", webData);
NSString *finalhtmlstring = [NSString stringWithFormat:#"%#", webData];
finalhtmlstring = [finalhtmlstring stringByConvertingHTMLToPlainText];
NSLog(#"FinalHTMLString is: %#", finalhtmlstring);
How would I fetch the body of the page? I can't get the NSString between #"<body>" and #"</body>", because some websites add attributes to the <body> tag.
It sounds like parsing XML or HTML page.
Fortunately, there is open-source libraries likes Hpple can help you to get the contents from wrappers easily.
It wraps libxml2 nicely using Objective-C objects
Here is a tutorial about how to use this library.
So I'm working on a small example on how to make a service call to a specific web service. I'm using the openweathermap.org web service. The link to this service is the following:
http://api.openweathermap.org/data/2.5/weather?q=London,uk
According to this link, I can search weather by city name. So I'm able to retrieve and NSLog the JSON data with the following code:
NSString *urlString = [NSString stringWithFormat:WXFORECAST, LOCATION];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(#"%#", json);
This does the bare minimum and retrieves the service. Now I would like to get my specific city instead of London.
If not, I would like to get JUST THE WEATHER part instead of getting the wind speed, and all that other garbage.
Here is the link for details on the API:
http://openweathermap.org/API#weather
Under that link there's a section that says this:
Restriction output:
To limit number of listed cities please setup cnt parameter api.openweathermap.org/data/2.5/find?lat=57&lon=-2.15&cnt=3
I believe this might be what I'm looking for but I don't know exactly how to use it...
All help is appreciated, thanks.
The API is accessed with a URL, try playing with this in your browser:
http://api.openweathermap.org/data/2.5/weather?q=New+York,us
See how I have a plus sign between "New" and "York"? That's to make sure the URL is valid, because they don't allow for spaces.
You have to figure out a way to get the URL you want in your variable. In your code, it's creating the URL using a format string stored in WXFORECAST. So, update that.
I don't have time to read through all of how that API works, but it's possible that you can't request that it gives you less information. But there's nothing stopping you from taking only what you need from it. It's all in that JSON dictionary, if you wanted to get the temperature your code might look like this.
NSArray *list = json[#"list"];
NSDictionary *london = list[0];
NSDictionary *main = london[#"main"];
NSString *temp = main[#"temp"];
I am currently trying to download the html code of a page for an app I am working on. For some reason when I try to download the code through
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://www.fedex.com/fedextrack/?tracknumbers=%#,#"Tracking#"]]];
I dont get the right HTML code however. When I set up the same load request through a UIWebView have it load then then get the HTML code from stringByEvauluatingJavaScript:#"document.body.innerhtml" I do get the right one.
My question is, how do I make the dataWithContentsOfURL work and get the right code?
I want to get URLs of all images or lets say "JPEG" files in a web directory (www.abcde.com/images). I just want their URLs in an array.. I couldnt manage that. Could u pls help me with this?
Thanks in advance..
Assuming you have access to an index file you could simply load via NSURL the whole html file and cut out the link lines. This however will not work (or hardly work) when you want to search ("spider or crawl") for links in more complex documents. On iOS i would suggest you use the simple, yet quite powerfull "hpple" framework (https://github.com/topfunky/hpple). It is used to parse html. You can search with it for certain html elements, such as <a href...> constructs.
a sample with hpple could looks like this:
NSURL *url = [NSURL URLWithString:#"whatver.com/images"];
NSData *data = [NSData url];
TFHpple *hppleParser = [TFHpple data];
NSString *images = #"//img"; // grabbs all image tags
NSArray *node = [hppleParser searchWithXPathQuery:images]
find a bigger example at http://www.raywenderlich.com/14172/how-to-parse-html-on-ios
Create a server side script(eg php) which gives you a list of all images in that directory as xml or json. From iOS send a request to that script get the xml or JSON parse it and use the image urls.