What's New in QuickTime 5

| Previous | Chapter Contents | Chapter Top | Next |

XML Event-Based Parsing

QuickTime 5 now includes an XML parsing component. In addition to tree-based XML parsing, it supports event-based XML parsing. This is supported through callbacks to the client.

Event-based parsing uses much less memory than the tree-based parser. Basically, it does a callback anytime something interesting happens. To invoke this, you pass the xmlParseFlagEventParseOnly flag to XMLParseDataRef() or XMLParseFile() . The XMLDoc parameter should be set to NULL in this case. The handlers (which need not all be set) are defined as follows:

ComponentResult startDocumentHandler(long refcon);
ComponentResult endDocumentHandler(long refcon);
ComponentResult startElementHandler(const char *name, const char **atts,
                                    long refcon);
ComponentResult endElementHandler(const char *name, long refcon);
ComponentResult charDataHandler(const char *charData, long refcon);
ComponentResult commentHandler(const char *comment, long refcon);
ComponentResult preprocessHandler(const char *name, const char **atts,
                                    long refcon);

The following APIs set the callbacks along with the common refcon shared among the callbacks:

pascal ComponentResult XMLParseSetEventParseRefCon(ComponentInstance
                                        aParser, long refcon);

pascal ComponentResult XMLParseSetStartDocumentHandler(ComponentInstance
                                        aParser, StartDocumentHandlerUPP
                                        startDocument);

pascal ComponentResult XMLParseSetEndDocumentHandler(ComponentInstance
                        aParser, EndDocumentHandlerUPP endDocument);

pascal ComponentResult XMLParseSetStartElementHandler(ComponentInstance
                        aParser, StartElementHandlerUPP startElement);

pascal ComponentResult XMLParseSetEndElementHandler(ComponentInstance
                            aParser, EndElementHandlerUPP endElement);

pascal ComponentResult XMLParseSetCharDataHandler(ComponentInstance
                            aParser, CharDataHandlerUPP charData);

pascal ComponentResult XMLParseSetPreprocessInstructionHandler(ComponentInstance aParser,
                                PreprocessInstructionHandlerUPP
                                preprocessInstruction);

pascal ComponentResult XMLParseSetCommentHandler(ComponentInstance
                                aParser, CommentHandlerUPP comment);

It is the client's responsibility to create and free any UPPs it sets. Also, the atts parameter returned in the start element and preprocess handlers is a character string array that contains the attribute name followed by the attribute value. The list ends with a null terminator.


© 2001 Apple Computer, Inc.

What's New in QuickTime 5

| Previous | Chapter Contents | Chapter Top | Next |