Alex Henderson added the comment: I have attached a proposed patch.
This makes some design decisions which I would like someone to review: a) To incorporate pretty-printing into the main write() method rather than adding a separate toprettyxml() method. Disadvantages: greater complexity of _serialize_xml(). Advantages: Reduced duplication of code, easy to add other pretty-printing (eg HTML) in the same way. b) Existing whitespace on the ends of existing text is mutated. Disadvantages: existing whitespace content may get changed. Advantages: Greater readability (which is the whole point), idempotence of pretty-printing. c) Not to add a trailing newline. I am undecided as to whether this is a bad idea or a good one, but am documenting it to ensure it gets visibility. Of these, I think b) is the only potentially controversial one, and notably its behaviour differs from minidom's toprettyxml. I think it's the right thing to do though; and for the cases where whitespace is important, perhaps we can respect the xml:space attribute when pretty-printing? http://www.w3.org/TR/xml/#sec-white-space If these design choices are deemed suitable I'm happy to update the patch to support pretty-printing HTML also. ---------- keywords: +patch nosy: +alex.henderson Added file: http://bugs.python.org/file30845/issue17372.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17372> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com