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.
Related
Is it possible to get information from a url?
For example, it would be possible to get the headline and the image through the following url:
http://www.farodevigo.es/deportes/2011/08/24/lopez-garai-herrera-equivoca-prescindiendo/574038.html
Try this - What's the best approach for parsing XML/'screen scraping' in iOS? UIWebview or NSXMLParser?
also http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
Yes, that is possible but I wouldn't reccommend it.
In general, parsing HTML is hard - it's probably badly formatted and you would have a hassle trying to work out which bits you wanted and which bits you didn't.
You are better off using this URL : http://www.farodevigo.es/elementosInt/rss/1 and using NSXMLParser - because it's RSS it's definitely going to be well formed and easy for you to understand :)
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.
Am able to parse
< name>Walmart< /name>
using xml parser
but how to parse
*< s:image link="http://i.walmartimages.com/i/p/00/02/72/42/77/0002724277837_500X500.jpg"/>*
using xml parse in iphone.
Thanks in advance
There are various ways of doing this. My personal favorite is using Xpath via TFHpple. Xpath is clearly documented and easy to understand at W3schools. Sorry, I can't link to it. Spam filter prevents it.
I've used this approach for all sorts of things, and it is also great to note that you can use this library with HTML data as well.
I got the solution......
No need to go to parser libraries...
We can parse such tags using NSXMLParser with the help of attribute concepts....
thanks for you all for helping me....
cheers
I am currently using NSXMLParser mathods to parse my data something like this :
But I found some good option as TouchXML .
I googled for some good example or tutorial
But I can't understand the XPathquery format and the parsing loops as done in this example
or this question
I just want to know how to parse a simple xml document like this :
<ElementsArray>
<ElementObject>
<element1></element1>
<element2></element1>
<ElementObject>
.
.
.
<ElementArray>
so can anyone give me example code or a link will also be useful.
The coolest part of using TouchXML is that you can use the Apple documentation for NSXML and simply replace the NS with C. So an NSXMLDocument is a CXMLDocument and an NSXMLNode is a CXMLNode, and so on. Just look at the Tree-Based XML Programming Guide from Apple for sample code and you should get a pretty good idea of how to use TouchXML with your XML documents. The section Querying an XML Document should give you what you need to use XPath effectively.
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