I am not that good with xml, but my basic xml file looks somthing like this.
<MAIN_HEADER>
<HEADER>
<TITLE>my_title</TITLE>
<AUTOR>DNL</AUTOR>
<NAME>John</NAME>
<AGE>abc</AGE>
<SEX>male</SEX>
<PLACE>abc</PLACE>
<INI_FILE>abc</INI_FILE>
</HEADER>
<MAIN_HEADER>
<HEADER>
<TITLE>my_title</TITLE>
<AUTOR>DNL</AUTOR>
<NAME>John</NAME>
<AGE>abc</AGE>
<SEX>male</SEX>
<PLACE>abc</PLACE>
<INI_FILE>abc</INI_FILE>
</HEADER>
To copy to clipboard, switch view to plain text mode
what I want to do is, I need to find 2-3 tags, say for example NAME & SEX and store the attribute(John,Male) in another variable.
until now, I have been able to make it read the xml file.
void MainWindow::XMLParser()
{
QString path
=MainWindow
::getWorkingDirectory()+"\\0_Config\\";
string = path + ui->ConfigFiles_combo->currentText(); \\THIS IS WHERE´IT DETERMINES WHICH XML FILE IT IS
qDebug()<<string;
//load the file
{
qDebug()<<"Failed to open the file";
}
else
{
if(!document.setContent(false))
{
qDebug()<<"Failed to load document";
}
file.close();
}
qDebug()<<"finished";
}
void MainWindow::XMLParser()
{
QString path=MainWindow::getWorkingDirectory()+"\\0_Config\\";
QString string;
string = path + ui->ConfigFiles_combo->currentText(); \\THIS IS WHERE´IT DETERMINES WHICH XML FILE IT IS
qDebug()<<string;
QDomDocument document;
//load the file
QFile file(string);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Failed to open the file";
}
else
{
if(!document.setContent(false))
{
qDebug()<<"Failed to load document";
}
file.close();
}
QDomElement root = document.firstChildElement();
qDebug()<<"finished";
}
To copy to clipboard, switch view to plain text mode
how do I make it search for the exact tag and store it inside another variable?
Bookmarks