Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76800

Option to sort attributes in QDomDocument::toString()



    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.13.0, 6.0.0, 6.0
    • XML: DOM
    • None
    • 9e75a4cca (dev)


      Saving a QDomDocument to file sometimes results in its elements' attributes being reordered.

      .e.g. the XML attributes in this QString:

      <root name="fred">
          <element1 c="a" d="b" f="c"/ >

      get reordered to:

      <root name="fred" >
          <element1 f="c" c="a" d="b" />

      I know that similar bugs were reported before and I have read them.

      The previous reasons to not consider attribute order was optimization.

      Instead of changing the default behavior, I propose adding an another option: a method or flag that makes it possible to save XML files with ordered attributes. Application developers would be able to choose whether they need it or not.


      Even if the XML standard does not care about the order of attributes, people may care. It is true that there are tools for comparing XML files, but XML is not only machine-readable. People sometimes need to read XML too, which is why we already have options for pretty printing XML and JSON. We even have options to change the size of indentation in XML, e.g. "QDomDocument::toString(int indent = 1)".

      XML can be tracked in SCM (for example, Git), and random rearrangments produce useless large diffs.


      It seems that Qt5 is at the end of its improvement period. Qt6 is on the roadmap, and I think it would be a good idea to introduce this feature before Qt6 is released.

      I want to help and can prepare patches if this feature request is approved.


        Issue Links

          For Gerrit Dashboard: QTBUG-76800
          # Subject Branch Project Status CR V



              Unassigned Unassigned
              pravorskyi Andrii Pravorskyi
              3 Vote for this issue
              6 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes