XML documentation stinks - help?

Simon John simoninusa2001 at yahoo.co.uk
Wed Sep 1 06:34:38 CEST 2004

No, that's the docs I'm talking about, it's awful IMO.

So far I've found a little bit of info on the xml.parsers.expat module,
and got the following working the way Perl does, but it seems to create
blank elements due to whitespace!

And it seems the expat module has been deprecated in favour of SAX?

import xml.parsers.expat

# read in xml file
sourcexml = open("test.xml", 'r')
xml_file = sourcexml.read()

# define handlers
def startHandler(name, attrs):
if attrs != {}:
# skip blank entries
print "start name:", name
print "start attribs:", attrs

def endHandler(name):
print "end name:", name

def charHandler(data):
print "char data:", data

# create parser
prs = xml.parsers.expat.ParserCreate()

# start handler
prs.StartElementHandler = startHandler

# end handler
prs.EndElementHandler = endHandler

# char handler
prs.CharacterDataHandler = charHandler

# parse xml

More information about the Python-list mailing list