Objective-C (Desktop) XML file/web page to NSTableView
I'm looking to retrieve an XML document from a private API, then parse it into a table view.
I've looked through a few articles but I can't find anything that has helped me fully.
Does anyone have any art开发者_开发问答icles, tutorials, examples, etc that can help me out?
Thanks in advance!
I'd say this can be split into two problems:
First: Parsing XML
There are two ways to do this: some like event-driven XML; I strongly prefer tree-based XML. You should read a little into each of those tutorials and see which makes the most sense to you; I bet you'll prefer one of them based on your past programming experiences.
Second: Using Table Views
Once you've parsed your XML into some sort of dictionary or custom object, you'll need to display that object's information in a table view. For that, I suggest bindings. This CocoaDevCentral tutorial explains how to use bindings to display information in an NSTableView. (It even covers using multiple table views to create a Mail.app-like interface, which you may or may not find useful.)
Or... An Alternative, Less Flexible Method
In the guide for tree-based XML, there's a section on binding NSXMLDocument objects directly to table views. If you're sure that you'll be modifying the XML in such a direct way (for example, if you were writing, say, an XML editor!), then maybe that's a good idea, and you should check out this sample project. Otherwise, it'll be inflexible and you'll have to change it soon as you add features.
Good luck!
I had a similar problem recently and settled on the TouchXML library http://code.google.com/p/touchcode/wiki/TouchXML It wraps the NSXML cluster of classes and is based on the commonly available Open Source libxml2 library. The TouchXMLHowTo page http://code.google.com/p/touchcode/wiki/TouchXMLHowTo was useful in getting started. With TouchXML you can use XPath, and I found this most similar to what I had done in Java.
精彩评论