[issue20198] xml.etree.ElementTree.ElementTree.write attribute sorting

bagrat lazaryan report at bugs.python.org
Thu Jan 9 02:35:08 CET 2014


New submission from bagrat lazaryan:

xml.etree.ElementTree.ElementTree.write method (and, as a derivative, xml.etree.ElementTree.tostring function) sorts attributes in lexical order. while an admissible behavior instead of the randomness inherited from ordinary dict, this prevents a picky user to have her own custom ordering by passing an OrderedDict to Element, SubElement and the like (i guess there are none). that is to say:

if
-----------------------------------
e = Element("tag", OrderedDict([("a", "a"), ("c", "c"), ("b", "b")]))
-----------------------------------
then both
-----------------------------------
tostring(e)
ElementTree(e).write("xml.xml")
-----------------------------------
will result in
-----------------------------------
<tag a="a" b="b" c="c" />
-----------------------------------
while the intention of the user was
-----------------------------------
<tag a="a" c="c" b="b" />

----------
components: Library (Lib)
messages: 207721
nosy: bagratte
priority: normal
severity: normal
status: open
title: xml.etree.ElementTree.ElementTree.write attribute sorting
type: enhancement
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20198>
_______________________________________


More information about the Python-bugs-list mailing list