constructor TSAXParser.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FLine := 0;
FColumn := 0;
FAttributeList := TSXPAttributeList.Create;
// create an instance of the Reader COM object
FReader := CreateComObject(CLASS_SAXXMLReader) as ISAXXMLReader;
// instantiate the handler classes
FErrorHandler := TSAXErrorHandler.Create;
FLexicalHandler := TSAXLexicalHandler.Create;
FContenthandler := TSAXContentHandler.Create;
FDTDHandler := TSAXDTDHandler.Create;
FDeclHandler := TSAXDeclhandler.Create;
FContentHandler.FDocumentLocator := Nil;
// Handlers need a reference pointing back to us
// because they will continually update
// our Line and Column properties on each event
FLexicalhandler.SAXParser := Self;
FContenthandler.SAXParser := Self;
FDTDHandler.SAXParser := Self;
FDeclHandler.SAXParser := Self;
// pass the handler implementations to the reader
FReader.putErrorHandler(FErrorhandler);
FReader.putContentHandler(FContentHandler);
FReader.putDTDHandler(FDTDHandler);
Freader.putProperty('http://xml.org/sax/properties/lexical-handler',
FLexicalhandler as ISAXLexicalHandler);
Freader.putProperty('http://xml.org/sax/properties/declaration-handler',
FDeclhandler as ISAXdeclHandler);
end;
Example 3: Constructor of TSAXParser instantiates the reader and the handler classes,
and passes the handlers to the readers.
Back to Article