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. QDomDocument add setAttribute in especific order
Forum Updated to NodeBB v4.3 + New Features

QDomDocument add setAttribute in especific order

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • F Offline
    F Offline
    fajung
    wrote on last edited by
    #1

    I'm having troubles with setAttribute from the QDomDocuments, I can't add the attributes in the order I'd like to. I can't figure out how to do it right

    @void XMLParse::AddSingleProduct(QString mes, QString pro, QString value){
    QDomDocument tmp("tmp");
    QDomNodeList Item = MonthNode(); // this place me into the <Meses>
    // int i = GetMonthIndexByName(mes); //
    // QDomNode q = Item.at(i-1); //

    QDomNode q = Item.at(0);
    QDomElement aaaa = tmp.createElement("Item");

    q.firstChildElement("Productos").appendChild(aaaa);

    aaaa.setAttribute("Nombre", pro);
    aaaa.setAttribute("Costo", value);

    this->Save(); // this save the xml file
    

    }@

    here is the xml in which I'm working on:

    @<?xml version='1.0'?>
    <Temp Year="2006">
    <Meses>
    <Enero>
    <Productos>
    </Productos>
    <Realizaciones/>
    <Facturcion/>
    </Enero>
    </Meses>
    </Temp>@

    no matter how or where I do the .setAttibute, it always add them in a differente order, I need to add this attributes in a especific order, please help

    To whoever has my voodoo doll: Scratch my buttcheek... I'm in public.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      AFAIK you can't do that with QDomDocument. The XML spec says nothing about order of the attributes (or rather says it's "not significant"), so it's an implementation detail in QDomDocument.
      You might have better luck with the QXmlStreamWriter if that's an option for you.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fajung
        wrote on last edited by
        #3

        should I use just QXmlStream or both(QXmlStream* & QDomDocument), to read, edit add delete, bla bla, .... from an xml file?

        I'm very new with Qt and I don't know wehere I'm.

        To whoever has my voodoo doll: Scratch my buttcheek... I'm in public.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          There are basically two ways to parse or write XMLs.

          One is DOM - this basically creates a tree of xml nodes and allows you to manipulate them - this one is handled by QDomDocument.

          The other one is SAX - it's an incremental parser. It reads(or writes) tag by tag without knowing surrounding nodes. This is handled by QXmlStreamReader/Writer.

          They don't mix. Choose one or the other.
          Here's an example for the writer: "Detailed Description":http://qt-project.org/doc/qt-5.1/qtcore/qxmlstreamwriter.html#details

          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