[XML-SIG] using PyXML on a string
Paul Tremblay
phthenry@earthlink.net
Thu, 22 May 2003 23:53:56 -0400
I would like to use SAX to parse a string rather than a file. Is there
a way? I know how to use expat directly to parse a string, and I know
how to use SAX to parse a file. However, one cannot use expat in the
way I like:
# code will break!
class ExpatDir:
def __init__(self):
self.__initiate_parser()
def __start_element(name, attrs):
print repr(name)
def __end_element(name):
print repr(name)
def __char_data(data):
print repr(name)
def __initiate_parser(self):
parser = xml.parsers.expat.ParserCreate()
parser.StartElementHandler = self.__start_element
parser.EndElementHandler = self.__end_element
parser.CharacterDataHandler = self.__char_data
self.__parser = parser
def parse_string(self, a_string):
self.__parser.parse(a_string)
This code will break becaue I am passing to expat a method rather than
a definition.
When I use SAX with python, I subclass my documenthandler in the
standard way, and then use parse(file).
Can I not use parse(string)?
Thanks
Paul
--
************************
*Paul Tremblay *
*phthenry@earthlink.net*
************************