Read live html file in NSData - iphone

I am working on my app where I have to read an HTML file:
The URL is http://www.youtube.com/user/danielmorcombefd/videos.
Then I want to save it as a HTML file, say example.html, and then store it's data in an NSData:
NSData *data = [[NSData alloc] initWithContentsOfFile:#"example.html"];
Kindly suggest me solutions.

-initWithContentsOfURL: perhaps?

Related

Display data on UI from XML in project iPhone

I need to know that i have a XML file, in my project I have some data in it.
How can i display that data in TableView, Tutorials given on internet serve the purpose to display XML data that is through some URL, i just want to display from my local file in project.
I assume you are using Objective-C, am I correct?
Have you tried using NSXMLParser. I would assume you would be able to just use the contents of the file in your project and parse it with NSXMLParser.
You might want to have a look at this NSXMLParser example
NSString *xmlFilePath=[[NSBundle mainBundle] pathForResource:#"TesingSampleXml" ofType:#"xml"];
NSString *xmlString=[[NSString alloc]initWithContentsOfFile:xmlFilePath];
NSData* xmlData=[xmlString dataUsingEncoding:NSUTF8StringEncoding];
xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
[xmlParser setDelegate:self];
[xmlParser parse];
Now Parse the data using the delegates of the NSXMLParserDelegates and then reload the tableview.
Best XML Parser tutorial
http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
To display data from xml file you need to parse the xml file. To parse file you can use any parser like - NSXMLParser, tbxml and so on
*I recommend TBXML * it is fast and light
go through this link for more details

how to access the content within the zip file in iphone

I have a zip file. In that zip file I have some ppt presentation.
I want to show that ppt presentation in my UIWebView.
I cannot extract and show ppt files there directly .
How do I access the ppt inside the zip in objective c?
This isnt easy. You might want to consider doing this another way. For example you could put the file unzipped on a server and open the link in a webview.
However, if you really want to do it this way there is 2 step.
1. Unzip the file.
You want end up with NSData. Read though some of the links suggested in the comments. You will need to use a 3rd party library to achieve this.
2. Load the data in to a UIWebView.
Write the NSData to the temp directory then point the UIWebView at it.
NSString *path = // .. Get a location in the NSTemporaryDirectory
if ([pptData writeToFile:path atomically:YES])
{
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}

hpple html parse iphone sdk help?

I want to parse html.. so I have found some sample code over: http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/
it uses hpple to parse html... but there is one problem this application is constantly crashing for some reason most probably it is this line over here:
NSURL *url = [NSURL URLWithString: #"http://www.objectgraph.com/contact.html"];
NSString *contents = [NSString stringWithContentsOfURL:url];
NSData *htmlData = [contents dataUsingEncoding:NSUTF8StringEncoding];
xCode gives me warning stringWithCOntentsofVariable is deprecated..
so could anyone help me solve this problem....by showing what code should I change?
thanks
30 seconds in the documentation shows:
Returns a string created by reading data from the file named by a given URL. (Deprecated in Mac OS X v10.4. Use stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error: instead.)
So, it looks like you should be using stringWithContentsOfURL:encoding:error or stringWithContentsOfURL:usedEncoding:error: instead.
Just like the documentation says.

To test working of xml in iphone?

HI can i place both xml files and images that the xml file transports in xcode to test the working since i don't have the internet ? If it can be done , what should be the path name for the xml to be coded in program and images to be typed in xml.?
NSString *stringToXML = [[NSBundle mainBundle] pathForResource:#"theXMLDoc" ofType:#"xml"];
NSURL *XMLURL = [NSURL fileURLWithPath:stringToXML];
Using that you can get XML documents from the resource folder and use them.
Just substitute your url in your code for the variable XMLURL and you should be fine. Its the same for images, you just need to make an NSURL out of the path resource.

iPhone - dataWithContentsOfURL: does not work for some URLs

I am using NSData to get content from a URL (RSS feed) and then parse it. While most of the URLs are loaded fine, some of them don't return any data.
These URLs open on the web so I know they are valid, but they just don't return any NSData. One such URL - feed://jpl.nasa.gov/multimedia/rss/rovers.xml
Here's how I am using it (the NSURL object is formed properly)
NSURL *feedURL = [NSURL URLWithString:[myUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *data = [NSData dataWithContentsOfURL:feedURL];
Any ideas why?
Thanks a lot.
Switch to NSURLConnection so you have some delegate methods to watch what's happening in debugger. check out the URL Loading System docs if you haven't.