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. Restore xml file formatting
Forum Updated to NodeBB v4.3 + New Features

Restore xml file formatting

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 851 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.
  • K Offline
    K Offline
    Kaluss
    wrote on last edited by
    #1

    Hi,
    I have following problem:
    I get the xml file from QNetworkReply.

       QFile newFile( "tmp.xml" );
       newFile.open( QIODevice::WriteOnly );
       newFile.write( reply->readAll() );
       newFile.close();
    

    The content is ok, but xml file is not formatted(all in one line).

    Does anybody know how can I restore xml formatting?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Use Qt Xml classes to read it in again ( or parse from reply->readAll())
      and write it to file formatted.
      You can give it directly to
      bool QDomDocument::setContent(const QString & text,..

      Something like ( not compiled. will have errors :)
      And please add error checking.

      void format(QByteArray xml)
      {
          QDomDocument doc; 
          doc.setContent(xml);
          QFile outFile("D:/output.xml");
          outFile.open(outFile.Text | outFile.WriteOnly);
          QTextStream stream(&outFile);
          doc.save(stream, DomNode::EncodingFromDocument);
      }
      
      1 Reply Last reply
      2
      • K Offline
        K Offline
        Kaluss
        wrote on last edited by
        #3

        @mrjj said in Restore xml file formatting:

        QDomDocument doc;

        Ok, it helped me a lot, but I suggest to use QDomNode::EncodingFromDocument option as a second parameter in save function.

        Thanks for help.

        mrjjM 1 Reply Last reply
        1
        • K Kaluss

          @mrjj said in Restore xml file formatting:

          QDomDocument doc;

          Ok, it helped me a lot, but I suggest to use QDomNode::EncodingFromDocument option as a second parameter in save function.

          Thanks for help.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kaluss
          Super.
          Fixed, thank you. :)
          ( magic values are evil )

          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