Restore xml file formatting
Solved
General and Desktop
-
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?
-
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); }