Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.13.0, 6.0.0, 6.0
-
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
- relates to
-
QTBUG-5364 QDomDocument::toString() generated file doesn't parse properly
- Closed
-
QTBUG-25071 tst_QDom relies on specific QHash ordering
- Closed
-
QTBUG-8158 QDomDocument save reorders attributes
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-76800 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
441705,6 | QDomDocument: ensure a defined order of attributes when saving | dev | qt/qtbase | Status: MERGED | +2 | 0 |