Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QDomDocument attribute ordering
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QDomDocument attribute ordering

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 8.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WilliamU
    wrote on last edited by
    #1

    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

    Regards,

    William

    1 Reply Last reply
    0
    • W Offline
      W Offline
      WilliamU
      wrote on last edited by
      #2

      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

      Regards,

      William

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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...

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • W Offline
          W Offline
          WilliamU
          wrote on last edited by
          #4

          OK Gerolf, thanks for the reply, and your comment about the weekend duly noted.

          --
          William

          Regards,

          William

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              WilliamU
              wrote on last edited by
              #6

              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

              Regards,

              William

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                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.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  WilliamU
                  wrote on last edited by
                  #8

                  OK, at least I know where I stand. Thank you all for your help, appreciated as always.

                  --
                  William

                  Regards,

                  William

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved