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

Regarding QDomDocument

Scheduled Pinned Locked Moved General and Desktop
30 Posts 5 Posters 18.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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #20

    With that badly formatted code there is no wonder that you do not find your errors. Do you really expect us to play the "where is the corresponding brace game" in that big mess?

    Please format the code nicely, first of all indent the blocks in a reasonable way, and edit your original post to update the code sections. We might come back and look at it then. Please leave a short comment in the comment box to notify of the update, so that the post shows up again in the listings.

    You might want to read http://www.catb.org/~esr/faqs/smart-questions.html before you continue.

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Indrajeet
      wrote on last edited by
      #21

      HI volker

      I edit window the code is appearing as nicely indented but when i see the preview it shows messed up indentation.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #22

        Why do you not construct the whole XML using QDom methods but open an XML template and try to modify and duplicate this? This is quite strange at best, as you have the structure of the XML hardcoded in your method anyways (by means of the huge if/else blocks).

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Indrajeet
          wrote on last edited by
          #23

          Hi volker

          I know it is redundant way,but is it possible to get the result withthe same.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #24

            "QDomNode::cloneNode() ":http://doc.qt.nokia.com/4.7/qdomnode.html#cloneNode should be your friend.

            http://www.catb.org/~esr/faqs/smart-questions.html

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

              Rajveer, why do you keep opening topics on the same issue?
              http://developer.qt.nokia.com/forums/viewthread/9240/
              http://developer.qt.nokia.com/forums/viewthread/8947/
              http://developer.qt.nokia.com/forums/viewthread/7905/
              http://developer.qt.nokia.com/forums/viewthread/7704/

              You don't seem to be making much progress, to be honest.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Indrajeet
                wrote on last edited by
                #26

                Hi All

                My XML tag format is as shown below
                @
                <INFO>
                <FIELD name = "ONE"></FIELD>
                .
                .
                .
                600
                </INFO>

                My final XML file should be like this

                <?xml version="1.0"?>
                <root>
                <INFO>....</INFO>
                <INFO>....</INFO>
                <INFO>....</INFO>
                <INFO>....</INFO>
                .
                .
                .
                50000
                </root>
                @
                I want to create a xml file with 50000 tags as shown above.

                Below is my code
                @
                QDomDocument mainDoc;
                QDomProcessingInstruction instr = mainDoc.createProcessingInstruction("xml","version="1.0"");
                mainDoc.appendChild(instr);
                QDomElement root = mainDoc.createElement("root");
                mainDoc.appendChild(root);

                QDomDocument doc;
                QString errMsg;
                int errLine;
                int errCol;
                

                QString strItemTemplateData;//In this i have my Tag INFO stored
                if (!doc.setContent(strItemTemplateData,false,&errMsg,&errLine,&errCol))
                {
                qDebug() << "Error in XML File format" <<endl;
                }
                for(int i=0;i<50000;i++)
                {
                QDomNode clonedNode = doc.cloneNode(true);
                root.appendChild(clonedNode);
                }
                QFile generatedFile(strXMLFileName);
                if (!generatedFile.open(QIODevice::WriteOnly))
                {
                qDebug() << "Error in Filet" <<endl;
                return;
                }
                QTextStream textStream(&generatedFile);
                mainDoc.save(textStream,4);
                generatedFile.close();
                @

                My code above is performing very slow i.e it is taking lot of time & also some times it is crashing.
                Can anybody tell me how to create such a big file with good performance.
                And While creating the TAGS i have to set values for each TAG items for which i have to check each attribute value and than set it.
                eg:
                @
                <FIELD name="ONE">USA</FIELD>
                @

                [EDIT: three dots are enough, Volker]

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #27

                  QDomDocument is not the way how to handle big XML documents, but you have been told numerous times:

                  http://developer.qt.nokia.com/forums/viewthread/9483/
                  http://developer.qt.nokia.com/forums/viewthread/9240/
                  http://developer.qt.nokia.com/forums/viewthread/8947/
                  http://developer.qt.nokia.com/forums/viewthread/7905/
                  http://developer.qt.nokia.com/forums/viewthread/7704/

                  So - please - stop creating topics on the same issue over and over again and stick to the ones you've already created.

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Indrajeet
                    wrote on last edited by
                    #28

                    Hi Lukas

                    Not in anyone of the links u pasted has mentioned that
                    QDomDocument is not the way how to handle big XML documents
                    So please see my question and purpose of my question.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #29

                      You may ask multiple questions in the same topic as long as they are related. There is no need to create a new one.

                      Your application is slow and/or crashes because either your code is broken or for the simple fact that QDomDocument represents the whole XML structure in memory. If your XML structure contains hundreds of thousands of nodes you simply run out of memory and your application crashes. This is why you've been shown how to use QXmlStreamReader / QXmlStreamWriter instead which does not suffer from this problem and/or how to restructure your XML design so it isn't that bloated.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #30

                        Moderator's note:

                        I have merged the two threads "XML File generation using QDomDocument" (was http://developer.qt.nokia.com/forums/viewthread/9483/) from September and "Problem in creating XML file using QDomDocument" (http://developer.qt.nokia.com/forums/viewthread/10663/) from today into this thread. The all are on the same topic.

                        Please stop creating new threads on the same topic.

                        Also, please mind to format your code so that it can be read easily. This includes proper indenting. I doubt that many people take care have a look your code anymore if it's so hard to read.

                        Overall, please read and understand: http://www.catb.org/~esr/faqs/smart-questions.html

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        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