XML and Cocoa

by Jason McIntosh

After having found Objective-C and Cocoa programming in Mac OS X to be a lot of fun, I've started work on my first big project, a DocBook-aware text editor. Unfortunately, there doesn't seem to be a lot of support for XML processing with Objective-C, at least not enough support to be obvious to a Cocoa newbie like me.




What I have found so far reminds me a little of what the Perl & XML scene looked like perhaps three or even four years ago: there is scattered support here and there, but no solutions that fill one with confidence. Here's some bits and pieces I've come across in my search:






Related Reading



Perl & XML

Perl & XML


By Erik T. Ray, Jason McIntosh






The Coconut Library contains an API for working with libxml2 -- wow, as a big fan of the XML::LibXML Perl module, I'd really like that. Unfortunately, these libraries are geared to work on on Unices other than Mac OS X, and I'm not sure how to get them into the right shape so that they'll compile with Project Builder. I'm not sure I'd want to anyway; from what I can make out of the scanty documentation, the library uses its own classes for everything, including strings, so it apparently assumes you have no Cocoa or AppKit frameworks on your machine already. Eh.




GNUStep also contains some tantalizing XML support, but again, this project's goal involves bringing Cocoa-like programming frameworks to platforms other than Mac OS X, and not extending OS X's own frameworks.



Subsume Technologies' STXML framework, on the other hand, is definitely for Mac OS X (so much so that it's only available as a binary). It reminds me a lot of Perl's XML::Simple module, except that the API it offers appears to be read-only, and thus it's not much use to me; I want to be able to parse a file into a memory structure, and then modify it while the user modifies the corresponding document. I suppose I could always punt and try subclassing the sucker, just to get started quickly.



(Meanwhile, I smiled to see that Subsume hosts the original DasBlinkenlights Mac screensaver program from 1992.)



Maybe the most promising thing I have found is the MPWXmlKit framework, a free and open project offered by Metaobject. Yay, it compiles in Project Builder (albeit with lots of warnings, and only after you compile and link in the same company's free MPWFoundation framework). Peek in the public headers: I see DOM! I see SAX! I know them! They are my friends! But I don't see any documentation or examples, and no class has an obvious way to feed it a file. I Perlishly expect to see at least one class defining a parseFromFile method. No dice there. Hmm. And the great Google is mum. Still rather intriguing...



Apple itself offers two XML solutions for Mac OS X programmers, both of which land wide to the net, as far as I'm concerned: a Java framework, and a Carbon library. Nothing for Objective-C? From Apple? Gee whiz.



I kind of wish there was something like CPAN for Cocoa frameworks. Oh well. My search continues...



Maybe I should just write the whole thing using the Cocoa-Perl bridge. That'll show 'em.


1 Comments

mweiher
2002-06-26 11:52:32
Examples Online
It looks like I forgot to put the XML examples online. They are now at http://www.metaobject.com/downloads/Objective-C/.