[SOLVED] QDomDocument attribute ordering
-
Hello all.
I am creating a QDomDocument from a database query. The query itself uses a (n empty) template so that every time I execute the query the element's attributes will be in the same position:
<stuff ID=' ' AttribA=' ' AttribB=' ' AttribC=' '>
...
</stuff>When I write the QByteArray to disk the XML source is in the 'correct order'. However, when I m_Doc->setContent(byteArray) and save the document the element's attributes are now in the 'wrong' order.
<stuff AttribA='' ID='' AttribC='' AttribB=''>
...
</stuff>Normally this would not be of consequence however my code (rightly or wrongly) assumes that the attributes will be in the same order as that of the original template, and since they no longer are the matrices I create from the data are now all wrong, and I become infeasible.
Could anyone tell me how I can preserve this order?
William
-
Hello again,
Can I assume that what I am asking for cannot be done, or have I missed the screamlingly obvious somewhere?
The only way I can see to fix this (for my own requirements at least) is to extract the attributes, sort them in a container then process them in alphanumerical order. But doing this means I have to re-write the (mathematical) model to use alphanumerically ordered inputs and this is something I would really like to avoid.
I would appreciate your thoughts on this please.
William
-
XML by default is not ordered. Afaik, with QDomDocument, you can't guarantee an attribute order.
By the way, please let the people time to answer, yesterday was weekend, not all people are here on weekend...
-
OK Gerolf, thanks for the reply, and your comment about the weekend duly noted.
--
William -
[quote author="Gerolf" date="1306747081"]XML by default is not ordered. Afaik, with QDomDocument, you can't guarantee an attribute order.[/quote]
Just to be clear: AFAIK, by default XML attributes are not ordered. XML elements are ordered. -
I'm not to sure if my use of the word ordered is causing confusion here. In my original question the attributes remain in the original order the are declared in the byte array of the XML file. When this byte array is assigned to the QDomDocument this 'order' is then lost and as a consequence my assumption about their physical orders no longer stands.
With this said I assume now that my only option is restructure my models and extract the attributes in alphanumerical order as I need to structure the matrices correctly.
--
William -
QDomDocument does not store the original stream, it stores values and tags in internal structures. On writing the document, it writes those values into the file.
For attributes, per definitions, orders do not matter, so QDomDocument does not take care of the order.
-
OK, at least I know where I stand. Thank you all for your help, appreciated as always.
--
William