1

Element is created:

        ele = doc.createElement("ele")   
        ele.attributes['var']= 'yes'
        ele.attributes['ret']= 'no'

        main.appendChild(ele)

But result has mixed attributes (alphabetic probably):

<function ret="no" var="yes"/>

Is there any way how to preserve the creating order of attributes in minidom?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
nich
  • 83
  • 2
  • 7

1 Answers1

2

No. The attributes are stored in a dictionary, and the order is not preserved. It shouldn't matter much anyway because the order of the attributes in XML has no semantic meaning.

You can use pxdom instead if you require the attributes in order for some reason.

Related

Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452