![]() |
Copyright (c) 1999, 2000, 2005, Todd Blanchard (tblanchard@mac.com). All rights reserved. |
What is it?
Expat is a stream-oriented XML parser. This means that you register handlers with the parser before starting the parse. These handlers are called when the parser discovers the associated structures in the document being parsed. A start tag is an example of the kind of structures for which you may register handlers.
ObjectiveExpat (formerly known as simply Expat and released in late 1999 with expat v 1.2) provides an abstract ObjectiveC class called TBXmlParser that represents an Expat parser and arranges for the parser's callbacks to call methods on the object. The Expat parser code is in the package, no need to get it elsewhere.
How do I use it?
TBXmlParser is an abstract class. If you want to get it to do anything interesting you need to subclass it and override the interesting methods such as
-(void)startElement:(NSString*)element withAttributes:(NSDictionary*)attributes;
-(void)endElement:(NSString*)element;
which are called at the opening or closing of a tag respectively.
I just want to parse some XML now!
There is a concrete subclass of TBXmlParser called TBXmlPListParser. It is a little bit like a DOM parser in that it builds an in memory representation of the XML document using PList objects (NSDictionary, NSArray, NSStrings). It was initially written as an example of how to create a functional concrete parser and to date it is still the only subclass I've bothered to make because it just works. If you want to build different data structures, your best bet is to subclass TBXmlParser and do your own thing.
The best way to think of it is TBXmlParser is analogous to a SAX parser, TBXmlPListParser is more like a poor man's DOM parser.
How do I use it?
TBXmlPListParser* parser = [TBXmlPListParser parserWithURL:[NSURL URLWithString: @"http://www.scripting.com/rss.xml"]];
NSLog(@"PList retrieved: %@",[parser propertyList]);
What is the license?
Expat and ObjectiveExpat is free software. You may copy, distribute, and modify it under the terms of the License contained in the file COPYING distributed with this package. This license is the same as the MIT/X Consortium license. If you use this package, I would appreciate an email and a mention in the developer credits. If you are feeling particularly grateful, you can make a donation towards ongoing support:
How do I get it?
http://homepage.mac.com/tblanchard/ObjectiveExpat/ObjectiveExpat1.95.8.zip
Can I get source code?
http://homepage.mac.com/tblanchard/ObjectiveExpat/ObjectiveExpatSource1.95.8.zip