[XML-SIG] example code?
Siggy Brentrup
bsb@winnegan.de
19 Dec 1999 18:17:20 +0100
"Michal Wallace (sabren)" <sabren@manifestation.com> writes:
[...]
> The docs say to override the "elements" dictionary, but:
>
> def elements["sometag"][0]():
> pass
>
> gives an error, and:
>
> def start_sometag(blahblah):
> pass
>
> elements["sometag"][0] = start_sometag
>
> just seems like the wrong thing to be doing.. What's the "right"
> way to do this? Does anyone have an example program I could borrow?
I'm an XML newbie myself, so there's NO WARRANTY whatsoever.
As from what I read from the xmllib docs you have to derive a class
along the following lines:
class MY_XML_PARSER(xmllib.XMLParser):
attributes = {
'SOME_TAG' : { 'ATTR' : 'DEFAULT_VALUE',
'NODFLT' : None,
},
}
elements = {
# Docs say 'function' try with bound method first
# if you get a wrong argument count error, drop
# "self.". If the latter succeeds, report documentation
# bug after crosschecking newest version of docs
'SOME_TAG' : (self.start_SOME_TAG, self.end_SOME_TAG),
# repeat for other tags
}
def start_SOME_TAG(self, attr_dict):
"""document start_SOME_TAG here"""
# do sth usefull
pass # just to be syntactically correct :)
def end_SOME_TAG(self):
"""document end_SOME_TAG here"""
# do sth usefull
pass # just to be syntactically correct :)
Note: this is completely untested, but hopefully isn't completely
wrong :)
not-quite-Cato-ly-yoUr's
Siggy
--
Siggy Brentrup - bsb@winnegan.de - http://www.winnegan.de/
****** ceterum censeo javascriptum esse restrictam *******