- Start Document--Receives notification at the beginning of the document.
- End Document--Receives notification at the end of the document.
- Start Element--Receives notification at the beginning of an element.
- End Element--Receives notification at the end of an element.
- Characters--Receives notification of character data.
- Processing Instructions--Receives notification of a processing instruction.
- Ignorable Whitespace--Receives notification of ignorable whitespace in element content.
- Reset Document--Resets document implementation defaults each time document is started.
- Set Document Locator--Receives a pointer to an object for locating the origin of SAX document events. The locator gives information on the location of the event in the XML document, such as line number and column position.
A few key methods must be called to initiate a SAX document parser and trap events:
- QxmlSAXParser_new--Creates a new instance of a SAX parser implementation and returns its pointer for reference.
- QxmlDocumentHandler_new--Creates a new instance of a Document Handler implementation with a parser instance created with QxmlSAXParser, returns a pointer for reference.
- QxmlSAXParser_setDocumentHandler--Connects the instance of a SAX parser with an instance of a Document Handler using their respective pointers.
- QxmlDocumentHandler_setCallback--Sets the callback procedure for one of the events previously listed. Takes a pointer to a Document Handler, event id (like StartDocument), and a pointer to the related procedure callback that handles the event.
- QxmlSAXParser_parse_systemId--Parses the XML document using a SAX parser. Given a pointer to a parser, a pointer to the name of an XML file, the CCSID of the XML file name, and a zero indicating null-terminated XML file name.
Once the parser is initiated with the QxmlSAXParser_parse_systemId method, registered callbacks are invoked as the related document nodes pass through the parser. Unlike the tree representation of DOM, SAX flattens the tree, expands each branch in turn, and siphons it through the parser pipeline. Because a tree is not built, SAX is more appropriate for large documents that do not require more than one access (since there is no tree to be traversed) and when the overhead associated with building a DOM tree is not a workable solution.
Jim D. Barnes is a senior developer and project lead at PentaSafe Security Technologies, Inc. in Houston, Texas. You may reach him by email at
LATEST COMMENTS
MC Press Online