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

Option to sort attributes in QDomDocument::toString()

    XMLWordPrintable

Details

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

    Description

      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"/ >
      </root>
      

      get reordered to:

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

      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.

      Rationale

      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.

      Qt6?

      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.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes