[XML-SIG] Simple DOM question (writing DOM)
Thomas B. Passin
tpassin@home.com
Wed, 12 Dec 2001 20:55:54 -0500
[Martin v. Loewis]
>...
>
> > This sounds a little bit too unstructured to me. Btw. I've meanwhile
> > got the transformation from/to XML working. I'm quite happy with it
> > and it's not too much work in comparison with print/write. Any
> > comments?
>
> Two of them:
>
> 1. Sometimes, people have specific ideas of how the XML should look
> like on a lexical level (what encoding to use, where to insert
> whitespace, etc). Producing a DOM tree and invoking .xml() does not
> give you that flexibility. It may not be needed in your
> application, so this might not be an issue.
>
> 2. Keep Unicode strings as long as you can. I see that you use
> .encode("utf-8") in fromxml, and put back the UTF-8 strings in
> toxml. Strictly speaking, this is breaking the DOM contract: All
> strings in DOM are Unicode; byte strings are only accepted for
> backwards compatibility. You should really carry over the Unicode
> objects, and keep them until you need to print them into a byte
> stream.
>
Remember, if you produce output strings, don't use
str=str+data
to build up really long strings - because it gets very slow (see a thread on
this a month or so ago). Either output short strings as you go, or put the
string pieces into a list then join the list, or use StringIO - that will be
MUCH faster.
Cheers,
Tom P