[XML-SIG] XMLFilterbase.

Alan Kennedy pyxml@xhaus.com
Thu, 11 Apr 2002 12:35:48 EST5EDT


Greetings All,

I had the occasion to use a SAX filter today, and thought 
I'd inherit from the saxutil.XMLFilterBase class, since I 
only needed to override a single method.

The saxlib.XMLFilter "interface" defines an __init__ method 
that takes a parent parser, as it should do. So basically 
the wrapped parser now becomes a "filtering parser", as far 
as the user of the parser is concerned, in that methods 
that control the parser should now be given to the filter, 
which then passes them onto the wrapped parser.

However, the XMLFilterBase class, which I would expect to 
inherit from XMLFilter, instead inherits from XMLReader. 
And, of course, the __init__ method from XMLReader doesn't 
take a parent parser as a parameter.

So when I subclass XMLFilterBase, override 1 method 
(startElement in this case), instantiate my subclass, 
passing a freshly created XMLReader as the parameter to the 
__init__, the instantiation fails because the 
XMLReader.__init__ method doesn't expect parameters.

Or maybe I'm just misunderstanding SAX2 filters?

As an aside, I'm not happy with SAX2 filters, in that they 
wrap the parser (XMLReader) rather than the handler 
(ContentHandler). It seems more natural to me to wrap the 
handler, and that's exactly what I've done in several 
(java) applications I've written, thus discarding the 
provided SAX2 filter mechanisms and writing my own. But 
that's not the only problems I have with the design of SAX2 
filters.

Anyway, if people think that the current superclass of 
XMLFilterBase is a bug, I'll report it/submit a patch over 
@ SourceForge.

Regards,

Alan Kennedy.


---------------------------------------------
This message was sent using WebMail by CyberGate.
http://www.gate.net/webmail