[XML-SIG] Bug in expatreader module...
Michael Aivazis
aivazis@caltech.edu
Sat, 16 Jun 2001 22:32:43 -0700
Achim Gaedke wrote:
>
> (This is the same topic as in comp.lang.python)
>
> Hello everybody!
>
> My intention is to write a recursive parser for nested data structures.
> In order to collect the data it is necessary to switch the
> contenthandler each step.
I ran into this problem some time ago. If I remember correctly, the
actual problem appears to be that setContentHandler does not do all the
work necessary to wire a new instance into the parsing loop. In
particular, as you point out, it does not set the character handler
correctly.
However, this bug forced me to rethink my solution to my problem. As it
turns out, it is possible to parse an XML file and construct a Composite
- a nested data structure - without requiring more than one
ContentHandler.
If I understand your problem correctly, the need for more than one
content handler is a consequence of the fact that you want to do
tag-specific handling of the data, including making an object of the
appropriate type and attaching it at the right spot in the nested data
structure. Rather than changing the content handler, you can register a
handler for each tag with a single content handler and let it dispatch
to the tag handler to deal with the data in the tag.
If this sounds remotely like what you are faced with, I can send you the
code and an example. If anyone else on this list is interested in this
problem, I would be more than happy to post all this.
Regards,
-- Michael Aivazis