#include "generatexml.h"
#include "ui_generatexml.h"
#include<QMap>
#include<QFile>
#include<QXmlStreamWriter>
#include<QMapIterator>
#include<QMessageBox>
#include<QDebug>
#include<QDebug>
#include<QSqlDatabase>
#include<QSqlError>
#include<QSqlQuery>
#include<qdebug.h>
#include<QSqlRecord>
GenerateXML
::GenerateXML(QWidget *parent
) : ui_xml(new Ui::GenerateXML)
{
ui_xml->setupUi(this);
setWindowTitle("Generate Xml");
connect(ui_xml->pushButton,SIGNAL(clicked()),this,SLOT(CreateXMLFile()));
// //**** CALLING FUNCTION *****
// CreateXMLFile();
// QObject::deleteLater();
}
GenerateXML::~GenerateXML()
{
qDebug("In Destructor---------------");
delete ui_xml;
}
void GenerateXML::CreateXMLFile()
{
QFile file("/mnt/jffs2/Synch.xml");
{
"GenerateXML::parseXML",
"Couldn't open example.xml",
return;
}
else
{
qDebug("THE FILE IS READ ONLY MODE --");
qDebug()<<"**************establishing new DB connection**************";
db2.setDatabaseName("/mnt/jffs2/apmcdb.sqlite");
bool ok1 = db2.open();
qDebug()<<"*(((((((((((((((((((("<<ok1;
if(ok1)
{
qDebug() << "Database opened";
}
else {
qDebug() << "Database not opened";
}
//*********** GETTING COLOUMN NAMES &&& DATA FROM TABLE **************
bool que=fardb.exec("SELECT * from something");
qDebug()<<"Query Check---------------"<<que;
qDebug()<<"no of coloumnss-----------"<<colnames.count();
qDebug()<<"colname----" <<colnames.fieldName(0);
//*********CREATING & WRITING TO XML FILE**********************
QXmlStreamWriter* xmlWriter= new QXmlStreamWriter();
xmlWriter->setDevice(&file);
xmlWriter->setAutoFormatting(true);
/*Start document */
xmlWriter->writeStartDocument();
xmlWriter->writeStartElement("MAIN");
while(fardb.next()) //entering to write row of query records
{
//*******start tag persons******
xmlWriter->writeStartElement("Record1"); //start new tag for one enitre row of record
for(int cols=0;cols<colnames.count();cols++) //gets the coloumns of the particular row
{
//writes each coloumn in new line with <colname_tag> col_value </colname_tag>
xmlWriter->writeTextElement(colnames.fieldName(cols),fardb.value(cols).toString());
}
xmlWriter->writeEndElement(); //end tag for row of record
//********end tag persons**********/
}//ends after writing last record row of query
xmlWriter->writeEndElement();
xmlWriter->writeEndDocument();
/*end document */
delete xmlWriter;
}
}
Bookmarks