How to generate XML

Fredrik Lundh fredrik at pythonware.com
Wed Feb 13 17:12:11 EST 2002


Michael Chermside wrote:
> >>> I'm amazed that people always start proposing difficult-to-use
> >>> libraries when this question comes up. I'd prefer to use
> >>>
> >>> print "<foo/>"
>
> I tend to agree with the original poster: simply writing your own print
> routines isn't difficult at all.

in my experience, it's not worth it: you always end up forgetting to
call cgi.escape at the right places, encode non-ascii strings properly,
make sure that your program doesn't explode when some function
returns a unicode string instead of a plain string, etc.

using print to write XML is not as bad as using RE to parse it, but
it's far from optimal.

Traceback (most recent call last):
  File "effbot.py", line 105, in ?
  File "SimpleXMLWriter.py", line 103, in end
    assert self.__tags, "unbalanced end(%s)" % tag
AssertionError: unbalanced end(F)





More information about the Python-list mailing list