[Qt-interest] 答复: ç"å¤ : QDomDocument parser xml
Jason H
scorp1us at yahoo.com
Wed Feb 23 16:16:20 CET 2011
I've used QXmlStreamWriter, but not as much as QDom. If you can sort your
attributes with it, then you are all set.
----- Original Message ----
From: pengliang(彭亮) <pengliang at founder.com>
To: Jason H <scorp1us at yahoo.com>; Andre Somers <andre at familiesomers.nl>;
qt-interest at trolltech.com
Sent: Wed, February 23, 2011 12:59:23 AM
Subject: 答复: [Qt-interest] ç"å¤ : QDomDocument parser xml
Hi
Thanks for your suggestions.
QDomDocument is not one and only class for me, I think QXmlStreamWriter is a
simply and quick class for me.
-----邮件原件-----
发件人: qt-interest-bounces+pengliang=founder.com at qt.nokia.com
[mailto:qt-interest-bounces+pengliang=founder.com at qt.nokia.com] 代表 Jason H
发送时间: 2011年2月21日 23:25
收件人: Andre Somers; qt-interest at trolltech.com
主题: Re: [Qt-interest] ç"å¤�: QDomDocument parser xml
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
_______________________________________________
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