Sax Handler
Mike Meyer
mwm at mired.org
Sat Nov 6 13:52:35 EST 2004
Juliano Freitas <jubafre at atlas.ucpel.tche.br> writes:
> hello!!!
>
> here is my pythn code that's handle a xml file:
>
> =============================================================
> from xml.sax import saxutils, saxlib, saxexts, parseString
>
> class swdbHandler(saxlib.DocumentHandler):
> def __init__(self):
> self.flag = 0
>
> def startElement(self, name, atts):
> if name == "swml":
> print "enter"
>
> def endElement(self, name):
> if name == "swml":
> print "exit"
>
> parser = saxexts.make_parser()
> parser.setDocumentHandler(swdbHandler())
>
> # here
> parser.parseFile(open("exemplo.xml"))
> =============================================================
>
> i want to parse a "xml string" not a file how can i pass my swdbHandler
> to this string?? with parseString? i try but doesnt work?
> somebody can help me with this??
Try the StringIO module. That will give you a file-like object for a string.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list