On closer inspection:
- Your code starts and encounters the <root> element
- isStartElement() is true
- You read the entire content of the <root> element to extract any immediate child text nodes
- There are no child text nodes... no output.
- The file is now exhausted.
A more selective scan is more fruitful:
#include <QtCore>
#include <QDebug>
int main(int argc, char *argv[])
{
QFile in
("categories-file.xml");
QXmlStreamReader s(&in);
while (!s.atEnd()) {
s.readNext();
if (s.isStartElement() && s.name() == "en_main") {
qDebug() << s.name();
qDebug() << s.readElementText();
}
}
}
return 0;
}
#include <QtCore>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QFile in("categories-file.xml");
if (in.open(QIODevice::ReadOnly)) {
QXmlStreamReader s(&in);
while (!s.atEnd()) {
s.readNext();
if (s.isStartElement() && s.name() == "en_main") {
qDebug() << s.name();
qDebug() << s.readElementText();
}
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
output:
"en_main"
"Automotive"
"en_main"
"Community (The Big Heart)"
"en_main"
"Electronics & HiTech"
"en_main"
"Events & Announcements"
"en_main"
"Hi Tech"
"en_main"
"Hobbies & Collectibles"
...
"en_main"
"Automotive"
"en_main"
"Community (The Big Heart)"
"en_main"
"Electronics & HiTech"
"en_main"
"Events & Announcements"
"en_main"
"Hi Tech"
"en_main"
"Hobbies & Collectibles"
...
To copy to clipboard, switch view to plain text mode
Bookmarks