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.
Related
I need to find a good tutorial that would guide me to write to a JSON file. and also to read from a JSON file and populate core-data with it.
I have googled for days, and couldn't find a good tutorial. Can someone give me a sample code or point me to a good tutorial. I am new to objective-c
to introduce the structure of JSON, http://json.org/
and if you scroll down, you will find links to several open-source (which you can use as examples) projects which implement JSON serializing and deserializing. basically, there, you will find much more code examples in their projects than anyone here can ever really post as a response to your question.
Hi desperate newbie in need of direction! Well I say newbie, I have almost built myself the app I set out to achieve, a tableview to display story titles from my website, that when touched using the navigation controller slides to the story/article.
Only problem is that I only have test data that is embedded into my views as an array (which is no good to me). I need this data to come from my website, www.theknowledgeoflondon.com. I want to take the title to display in the tableview and then when touch it slide to the actual article.
Been reading up and believe that JSON could be the answer or XML? I do not have a clue on this subject and if I thought learning object c and coco touch was hard this JSON OR XML thing seems to be a new world of PAIN for me!!! and there doesn’t seem to be anything by way of good tutorials out there for someone that has not a clue on the subject. My data is drawn from a simple MySql table from a php script and was hoping there is an easy way to feed this into my table view?
Would be very greatful for any information on a good way forward. Have already downloaded SBJson, but then read that JSONTouch is a good alternative to use. Or should I be using straight XML. Any help and good tutorials would be much appriciated.
Thanks you in advance.
Steve
I made an app last week that uses XML and I found it the easier way of doing what you want to do. But I found an awesome tutorial that I believe is perfect for what you are trying to do. It helps you create the web service needed and teaches you how to access the data that you wish to access.
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
and also check
http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service
And for even more information on web related subjects also have a look at www.w3schools.com it is an amazing website dedicated to teach about web technologies such as XML and the like.
Hope it helps you as much as it has helped me.
If you have the option to choose then I will suggest to use plist format. Open a plist file with a plain text editor. You will find that that is actually a XML file. The big advantage of using plist is that you don't need another parser. You can convert a plist file directly to NSArray using arrayWithContentsOfFile or arrayWithContentsOfURL or convert them directly to NSDictionary by using similar methods. And you can create them using plist editor of Mac easily.
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.
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