Display data on UI from XML in project iPhone - 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

Related

Read live html file in NSData

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?

Read XML and show it at an TableView

I want to do something very simple - read a XML from the web and then show (in a TableView) the contents of the titulo in the xml.
Here's what it looks like:
<?xml version="1.0" ?>
<lista>
<edicao>
<ano>2011</ano>
<mes>1</mes>
<titulo>01/2011</titulo>
<file>01-2011.pdf</file>
</edicao>
<edicao>
<ano>2010</ano>
<mes>4</mes>
<titulo>04/2010</titulo>
<file>04-2010.pdf</file>
</edicao>
</lista>
I've searched a lot, but I was unable to find how to do it. Most of the examples already had a class named XMLParser that I don't know how to create. I looked at the libraries too, but I just can't find out how to do it. If anyone can advise me how to do this it would be great. Thank you!
Here is a tutorial that shows XML parsing using GDataXMLParser.
how-to-read-and-write-xml-documents-with-gdataxml
GDataXMLParser is better than NSXMLParser since latter is slower.
The Cocoa framework provides an XML parser class called NSXMLParser. You can find out more about it at http://developer.apple.com/library/ios/#documentation/cocoa/reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/occ/cl/NSXMLParser.
There is already a great library out there that makes it really easy to parse XML files.
It is called TouchXML and you can find it on github here.
There are a bunch of tutorials online but is is very easy to use.
This is the one I learned with.
http://www.edumobile.org/iphone/iphone-programming-tutorials/parsing-an-xml-file/
This helped me...Crate .h and .m from the XMLParser.h and .m then just copy paste the code in it. and use the cell creation function as given in example.
Use the NSXMLParser class with the NSXMLParserDelegate methods. You must be init the parser:
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://www.site.com/example.xml"];
parser.delegate = self;
[parser parse];
And use the delegate methods.

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.

Identify Html tags on Xml parsing

I am doing an xml parsing and the response i am getting is a html code ..is it possible to load that response in a uiwebview..?
Thanks in advance
The following methods are probably going to be what you're looking for:
[webView loadHTMLString:NSString baseURL:NSURL];
[webView loadData:NSData MIMEType:NSString textEncodingName:NSString baseURL:NSURL];
You can pass an NSString or NSData object to the appropriate method and have it loaded into your webView easily.
Good luck,
Aurum Aquila
P.S. Those method signatures are hyperlinked.

loading and formatting the rtf file in UIWebView

I am trying to load the contents of a rtf file in the UIWebView. I am successful in loading the contents, but it is unformatted. the fonts are too large and it doesn't have any format. it displays the color of the rtf content, but not the font or size.
So what should i do now. is there any other way to load the rtf and format it? I load the rtf in following way:
NSString *path = [[NSBundle mainBundle] pathForResource:#"Home" ofType:#"rtf"];
NSURL *url=[NSURL fileURLWithPath:path];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[menuWeb loadRequest:req];
So what should i do now?
Use HTML instead, it's the only way you're going to get the control you want.
http://cutesoft.net/example/editRTF.aspx
This page is a WYSIWYG HTML generator. It generates extremely clean HTML (*), which I can then save and insert in my project. I can then modify this HTML file from within Xcode. All very nice!
(*) provided you use it right... flip between the normal view, HTML view and final view -- don't make it export into the second text box otherwise everything comes out in an impenetrable chunk.