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.
精彩评论