I have an xml file like this:
<start_header>
"text1"
"text2"
</start_header>
<option>
"text3"
"text4"
</option>
...and so on
<start_header>
"text1"
"text2"
</start_header>
<option>
"text3"
"text4"
</option>
...and so on
To copy to clipboard, switch view to plain text mode
I'd like to extract just the Textelement between each pair of tag and write it
in a file.txt
File.txt content:
"text1"
"text2"
"text3"
"text4"
I use the special class QXmlStreamReader and i try to obtain this behaviour with this code:
std::cout<<"f problem"<<std::endl;
std::cout<<"f problem"<<std::endl;
QXmlStreamReader xml(file);
while(!xml.atEnd()){
if (xml.readNext() == QXmlStreamReader::StartElement)
out<<xml.readElementText()<<"\n";
}
f->close();
file->close();
QFile *file=new QFile("source.xml")
QFile *f=new QFile("output.txt");
if(!f->open(QIODevice::ReadWrite))
std::cout<<"f problem"<<std::endl;
if(!file->open(QIODevice::ReadWrite))
std::cout<<"f problem"<<std::endl;
QTextStream out(f);
QXmlStreamReader xml(file);
while(!xml.atEnd()){
if (xml.readNext() == QXmlStreamReader::StartElement)
out<<xml.readElementText()<<"\n";
}
f->close();
file->close();
To copy to clipboard, switch view to plain text mode
The output file wasn't writed......
What's wrong with this code?
Is there an other method, to obtain the behaviuor I looked for?
Bookmarks