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. How to put the content of these 4 XML files into one XML file?
Forum Updated to NodeBB v4.3 + New Features

How to put the content of these 4 XML files into one XML file?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.1k Views
  • 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.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by sankarapandiyan
    #1

    I have Created the four windows (Four Forms) and i linked together by using signal slot..For example, if i click next button in the 1st window the 2nd window opens ,like wise i do for all remaining as well as i have store the combobox text in xml by clicking next button ,So i created 4 xml and now if i press the ok button in the first page i want to link all xml and i want to show in all in one XML ,I tried a lot but i cant't please try and help me to resolve it Guys ..

    firstpage code

           QString filename1 = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/home/newuser/Desktop/filenamemw.xml";
       QFile file("/home/newuser/Desktop/filenamemw.xml");
       if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
       qDebug() << "Open the file for writing failed";
      } else {
        QTextStream stream(&file);
        stream << document.toString();
        file.close();
        qDebug() << "Writing is done";
    

    second page code,
    QFile file("/home/newuser/Desktop/setting1xmlpage2.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    return;

    third page code,

      QFile file("/home/newuser/Desktop/setting2xmlpage3.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return;
    
    
    
    QXmlStreamWriter stream(&file);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    

    fourth page ,

            QFile file("/home/newuser/Desktop/setting3xmlpage4.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return;
    
    
    
    QXmlStreamWriter stream(&file);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    

    Thanks in advance

    jsulmJ 1 Reply Last reply
    0
    • sankarapandiyanS sankarapandiyan

      I have Created the four windows (Four Forms) and i linked together by using signal slot..For example, if i click next button in the 1st window the 2nd window opens ,like wise i do for all remaining as well as i have store the combobox text in xml by clicking next button ,So i created 4 xml and now if i press the ok button in the first page i want to link all xml and i want to show in all in one XML ,I tried a lot but i cant't please try and help me to resolve it Guys ..

      firstpage code

             QString filename1 = QDesktopServices::storageLocation(QDesktopServices::DataLocation)+"/home/newuser/Desktop/filenamemw.xml";
         QFile file("/home/newuser/Desktop/filenamemw.xml");
         if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
         qDebug() << "Open the file for writing failed";
        } else {
          QTextStream stream(&file);
          stream << document.toString();
          file.close();
          qDebug() << "Writing is done";
      

      second page code,
      QFile file("/home/newuser/Desktop/setting1xmlpage2.xml");
      if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
      return;

      third page code,

        QFile file("/home/newuser/Desktop/setting2xmlpage3.xml");
      if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
          return;
      
      
      
      QXmlStreamWriter stream(&file);
      stream.setAutoFormatting(true);
      stream.writeStartDocument();
      

      fourth page ,

              QFile file("/home/newuser/Desktop/setting3xmlpage4.xml");
      if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
          return;
      
      
      
      QXmlStreamWriter stream(&file);
      stream.setAutoFormatting(true);
      stream.writeStartDocument();
      

      Thanks in advance

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sankarapandiyan I don't understand your description: do you want to put the content of these 4 XML files into one XML file?
      Why not simply write all the content into one XML file from the beginning instead of writing into 4 files and then merging them?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      6
      • sankarapandiyanS Offline
        sankarapandiyanS Offline
        sankarapandiyan
        wrote on last edited by sankarapandiyan
        #3

        @jsulm yes ,you are saying right but i am not aware of this at my starting point ...

        : do you want to put the content of these 4 XML files into one XML file?

        yes you are ryt!.please try to resolve it please

        JonBJ 1 Reply Last reply
        0
        • sankarapandiyanS sankarapandiyan

          @jsulm yes ,you are saying right but i am not aware of this at my starting point ...

          : do you want to put the content of these 4 XML files into one XML file?

          yes you are ryt!.please try to resolve it please

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @sankarapandiyan
          Given that they are currently separate, I'm not sure what you want to do from here? Do you want to merge them into a single file and from then do it that way from now onwards?

          I do everything I can with XML documents rather than streams, it's just easier. To merge this way you will need to:

          1. Read each of your files into its own http://doc.qt.io/qt-5/qdomdocument.html

          2. Use http://doc.qt.io/qt-5/qdomdocument.html#importNode to import into one of them each of the others. You should be able to just import the other documents' http://doc.qt.io/qt-5/qdomdocument.html#documentElement, IIRC, so just one node.

          3. Save the QDomDocument you've imported the others into.

          sankarapandiyanS 1 Reply Last reply
          5
          • JonBJ JonB

            @sankarapandiyan
            Given that they are currently separate, I'm not sure what you want to do from here? Do you want to merge them into a single file and from then do it that way from now onwards?

            I do everything I can with XML documents rather than streams, it's just easier. To merge this way you will need to:

            1. Read each of your files into its own http://doc.qt.io/qt-5/qdomdocument.html

            2. Use http://doc.qt.io/qt-5/qdomdocument.html#importNode to import into one of them each of the others. You should be able to just import the other documents' http://doc.qt.io/qt-5/qdomdocument.html#documentElement, IIRC, so just one node.

            3. Save the QDomDocument you've imported the others into.

            sankarapandiyanS Offline
            sankarapandiyanS Offline
            sankarapandiyan
            wrote on last edited by
            #5

            @JonB said in How to put the content of these 4 XML files into one XML file?:

            I'm not sure what you want to do from here?

            @JonB said in How to put the content of these 4 XML files into one XML file?:

            Do you want to merge them into a single file

            yes i want to merge ...

            @JonB sure i will try

            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