[XML-SIG] example code?
Siggy Brentrup
bsb@winnegan.de
19 Dec 1999 19:31:59 +0100
"Michal Wallace (sabren)" <sabren@manifestation.com> writes:
> On 19 Dec 1999, Siggy Brentrup wrote:
>
> > As from what I read from the xmllib docs you have to derive a class
> > along the following lines:
>
> Thanks, Siggy.
>
> Yup, that works.
Thanks for testing :)
> It seems kind of odd to me that your code for handling
> one tag is spread out over four different places.. But I guess that's
> just me. Thanks. :)
That's quite easy with Python,
class XMLTag:
"""abstract base class for XML tags"""
def __init__(self, name, parser):
parser.attributes[name] = self.attributes
parser.elements[name] = self.handle_start, self.handle_end
class SOME_TAG(XMLTag):
attributes = {
'SOME_ATTR' : 'default value',
# ...
}
def __init__(self, parser, *OTHER_ARGS):
XMLTag.__init__(self, self.__class__.__name__, parser)
def handle_start(self, attr_dict):
# do sth usefull
pass
def handle_end(self):
# do sth usefull with all that stuff
pass
class MY_XML_PARSER(xmllib.XMLParser):
attributes = {}
elements = {}
def __init__(self, *OTHER_ARGS):
apply(SOME_TAG, (self,)+OTHER_ARGS)
As before, NO WARRANTY whatsoever.
not-quite-Cato-ly-yoUr's
Siggy
--
Siggy Brentrup - bsb@winnegan.de - http://www.winnegan.de/
****** ceterum censeo javascriptum esse restrictam *******