BSSAXTweetParserDemo / BSSAXTweetParser.h

//  BSSAXTweetParser.h
//  BSSAXTweetParserDemo
//  Created by Brent Simmons on 6/3/10.
//  This code is public domain.

#import <Foundation/Foundation.h>
#import <libxml/tree.h>

@class BSTweet;

@interface BSSAXTweetParser : NSObject {
	xmlParserCtxtPtr xmlParserContext;
	NSMutableData *characters;
	BOOL storingCharacters;
	NSMutableArray *tweets;
	BSTweet *currentTweet;
	BOOL parsingTweet;
	BOOL parsingUser;

- (void)parseData:(NSData *)entireXMLDocument; //Great for demo, bad for production

/*If you're doing it right, you're not storing the entire document in memory.
 You can parse it in sequential chunks of data. But this demo isn't doing it right.
 Also, there should be NSErrors in all this. There's, like, no error handling in this demo code. Caveat schmaveat.*/

- (void)startParsing:(NSData *)initialChunk;
- (void)parseChunk:(NSData *)chunk; //Parse just the next part
- (void)endParsing;

- (void)abortParsing;

@property (nonatomic, retain, readonly) NSMutableArray *tweets; //Array of BSTweet objects

/*If you did a lot of SAX parsing, you'd create a SAX parser class and then create a subclass for each specific parser.
 But for the sake of the demo I didn't do it that way.*/