[Qt-interest] ç­"复: QDomDocument parser xml

Andre Somers andre at familiesomers.nl
Mon Feb 21 13:13:14 CET 2011


Op Ma, 21 februari, 2011 12:47 pm, schreef Atlant Schmidt:
> André:
>
>   Well, I can think of one reason why it would have
>   been nice to keep the attributes ordered:
>
>   Random swapping around of attributes leads to new file
>   versions appearing to be different when they really
>   aren't. This confuses the history maintained by code
>   management systems, leads to extra work (and a greatly-
>   increased likelihood of errors) by the humans doing
>   code review ("Is this a real change or just Qt swapping
>   attributes around? I don't know, we'll have to inspect
>   each attribute individually and hope we correctly assess
>   all of the changes :-(."), and screws up a lot of
>   automation that expects that files don't gratuitously
>   change.

OK, point taken. I think this is only an issue if there are multiple tools
(including non-Qt tools) manipulating XML files that are stored in some
kind of versioning system. That happens, I guess, though I'd guess it's
not such a common use case.

Note that the order of the attributes does not randomly change. If you
load and save the same set of attributes, they will still be in the same
order for an XML file that was written away with QDomDocument. An order is
maintained internally, and though that order may not look "ordered" to the
naked eye, it is in fact ordered*. The order could in theory change
between versions though.

I am not sure if QXmlStreamWriter maintains the order of the attributes.
Without looking at the source, I'd guess that would be the case due to the
stream-character of the class, but I am not sure. It would be worth a
look.

André

*) Though I would not be too suprised if there are corner cases for cases
where the hashes of the attributes collide.




More information about the Qt-interest-old mailing list