Expatobjc is a small library that allows you to use James Clark's Expat XML parser library more easily with Objective C. It provides an object-oriented interface to the library which is similar to SAX2.
To use it, make a subclass of the XMLParser object that will override any or all of the following methods based on what parts of the XML parser document you want to read and analyze:
If namespace processing is active, the element names given to startElement and endElement are separated by the separator character given when the parser is first created, e.g. with a separator '|', an element start tag that looks like:
will appear to the startElement method as the string 'http://www.example.com/abc|test', just as namespace processing in Expat works.
You must also provide a replacement for the dataRead method, which is used by the parser to actually obtain text that is to be parsed as XML. Optionally, you may also provide a replacement for the errorHandler method, which will allow you to catch errors in the parsing of the text (the default handler will print the error code, line number, and error text and terminate your program).
Send an init message to initialize the parser object, giving it the default encoding you want, the separator character for the URI qualifier and the local name for XML namespace processing (ignored if namespace processing is disabled), the size of the buffer you want the processor to be using, and mask bits for what handlers you want to activate from this list:
Do a bitwise OR (with the '|' operator) to select which of these you need. To activate everything, use the XML_PARSE_ALL mask. It's probably preferable to just activate what you need, to avoid the overhead of spurious function calls and messages during parsing, it's much faster. XML_PARSE_DEFAULT, if ORed with any mask, will parse any data which would not otherwise have been visible with the above.
To begin parsing send a start message to the parser object. It should then begin parsing the document it obtains from the dataRead method.
For more details about the API and the exact form of the methods, read the XMLParser.h interface in the source distribution. For more information, read the Expat documentation. For an example of how to use the library, see the testparser.m code, which basically replicates the example in Clark Cooper's XML.com article on Expat, using the object-oriented interface.
You can go get it from the Sourceforge Project Page. You will need GCC compiled with support for Objective-C, and of course Expat.
I want your feedback on this program. You know how to reach me...