Reading a xml file and parsing it using DOM parser
I am not that good with xml, but my basic xml file looks somthing like this.
Code:
<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>
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.
Code:
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";
}
how do I make it search for the exact tag and store it inside another variable?
Re: Reading a xml file and parsing it using DOM parser
Your setContent() line is wrong, it is not getting the file.
Anyway, QDomDocument::elementsByTagName().
Cheers,
_
Re: Reading a xml file and parsing it using DOM parser
The example you show isn't valid XML. It should have a closing tag for <MAIN_HEADER>, as in </MAIN_HEADER>.