[Qt-interest] ç"å¤�: QDomDocument parser xml
Jason H
scorp1us at yahoo.com
Mon Feb 21 16:25:07 CET 2011
It is a trivial matter to write a function that will take a QDomNode and
recursively serialize it, alphabetically sorting attributes before outputting
them. You will need to write everything out yourself, but that is trivial.
Once you have sorted output, then everything you wish to do, you can. (liek
modify the dom tree, then compare if it matches a previous version)
----- Original Message ----
From: Andre Somers <andre at familiesomers.nl>
To: "qt-interest at trolltech.com" <qt-interest at trolltech.com>
Sent: Mon, February 21, 2011 7:13:14 AM
Subject: Re: [Qt-interest] ç"å¤�: QDomDocument parser xml
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.
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list