ich bastel gerade an einem Programm zum bearbeiten von XML-Files.
Ich habe die folgenden beiden Slots:
Code: Alles auswählen
void MainWindow::openFile()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), xmlPath, tr("XML files (*.xml);;") );
if (!filePath.isEmpty())
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly))
{
qDebug( "MainWindow::openFile(): File could not be opened" );
return;
}
QString errorMessage;
int line, col;
if (!xmlDoc.setContent(&file, &errorMessage, &line, &col)) //xml.Doc = QDomDocument
{
qDebug( "MainWindow::openFile(): Error in Line: %d Col: %d s",line,col,qPrintable(errorMessage) );
return;
}
xmlPath = filePath;
file.close();
}
}
void MainWindow::saveFile()
{
QString filePath = QFileDialog::getSaveFileName(this, tr("Open File"), xmlPath, tr("XML files (*.xml);;"));
if (filePath.isEmpty())
{
qDebug( "MainWindow::saveFile(): FilePath is empty" );
return;
}
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly))
{
qDebug( "MainWindow::saveFile(): File could not be opened" );
return;
}
QByteArray data = xmlDoc.toByteArray();
file.write(data);
file.close();
}Zum einen ist das XML-File welches ich öffne 31kb groß.
Das was ich abspeicher aber 88kb obwohl ich beim ersten hinschauen keinen Unterschied sehe.
Zum anderen sind die Attribute der DomElemente in ihrer Reihenfolge vertauscht, was das anschl. Lesen in einen Editor oder ähnlich sehr erschwert.
Kann mir einer helfen?
Danke und Gruß