XML with Cocoa Touch - iphone

I am a new learner at the area of Objective-C. I would like to retrieve data from XML page on the iPhone. Is it possible? It would be more helpful to me if I get an appropriate suggestion or code.

The SDK comes with the NSXMLParser class. Some people prefer to use the libxml2 library as it can be faster and more memory efficient than NSXMLDocument but you may want to wrap it with an Objective C layer as it is a C API. See this example.

There was a good episode of cocoaFusion: the other day that covered the ins and outs of XML parsing. Head on over to cocoafusion.net and look for Episode 2: An intro to using web APIs and XML.
The show notes section for that episode has some sample code downloads and links to other sites that contain more information (including some of the links mentioned in the other answers here).
Cheers!

A good article that lays out how you can use NSXMLParser to rip through xml.
Parsing XML in Cocoa

There is also some other libraries: TouchXML, KissXML.

Check out the SiesmicXML tute on Apple's iPhone developer site. It uses the XMLParser in a dedicated thread to parse XML in a backgroud process.
JK

Related

How to use NSXMLParser?

I have some XML which I need parsed in my Objective-C code. The XML is fairly simple. I have already searched Stackoverflow as well as Google but I did not find what I am looking for. Examples if how to use NSXMLParser would be useful, and if anyone has any suggestions on how to do this another way please let me know.
Did you look at the Apple sample applications? From the NSXMLParser class reference, I found no fewer than five sample projects that did parsing.
GKTank
KMLViewer
LazyTableImages
SeismicXML (probably your best bet, and most directly related)
XMLPerformance
I recommend going through this tutorial by Ray Wenderlich:
http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml
It uses GDataXML, which from my experience is a light-weight easy to use XML parser. It goes through all the basic steps to read and write to an XML document in a specific directory, including making or ammending to the file if it doesnt exist or exists respectively.

Simple XML parsing

Is there a simple way of parsing XML within iPhone app's?
I have been using NSXMLParser and I have heard of libxml2 - I am correct in stating that these are my only two options.
I just don't want to go down a long road when there is something simply that I can use.
There is also TouchXML which is nice and straight forward.
This blogpost gives a great overview of the most common XML parser available for iPhone (build - in and 3rd - party)

How To Parse A Website?

Hey I would like to build an app that could parse a website in order to get specific information. Specifically something that can parse http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=681780934297262 for the important information. Is there a tutorial out there I could use.
This Cocoa With Love article discusses parsing XML and HTML with the libxml2 library that is available with Xcode, using XPath to pull out the node(s) of interest. Take a look at the PerformHTMLXPathQuery() function.
Try this tool: http://code.google.com/p/sitescraper/

NSXMLDocument replacement on iPhone?

I have seen how an NSXMLDocument can parse an html document and provide easy methods for returning parts of the html structure.
Is there a similar method that can be used for the iPhone, as NSXMLDocument is not available?
Have you seen TouchXML?
http://code.google.com/p/touchcode/wiki/TouchXML
You might try this small document class which simply uses NSXMLParser:
https://github.com/nfarina/xmldocument
Also see this blog post:
http://notes.bikemonkey.org/post/47351363/googles-nsxmldocument-replacement-for-iphone
Google has written a replacement for some NSXML stuff for iPhone.

Web search in an iPhone app

I've got experience in C/C++ and am trying to now learn Objective-C for iPhone development. I have very little web design experience.
I'm trying to create an app for a friend's site that accesses a search feature from a website and then display the results in a UITableView. For example, (this isn't the site I'll be using, but...) using the stackoverflow search function and then being able to format the results (https://stackoverflow.com/search?q=iphone+web+search) in cells. I'd like to leave out the rest of the content on the page.
I've only been able to find info about reading xml or rss search results. Otherwise, I could use UIWebView, but that displays the entire site. Are there other classes that I should look into for doing this? Any help would be very, very much appreciated!
The iPhone SDK doesn't include Cocoa libraries for parsing HTML. Just NSXMLParser, which isn't a good tool for what you want to do. (It will choke on valid HTML that isn't valid XML.)
This page is probably a good first place to look. The author says, "For scraping/reading a webpage, XPath is the best choice. It is faster and less memory intensive then NSXMLParser, and very concise. My experience with it has been positive."