I Have a question concerning reading an XML file:
<table>
<100000 />
<100001 name="void" type="ref" cat="ref"/>
<100002 name="noref" type="err" cat="ref"/>
<100003 name="notype" type="err" cat="ref"/>
<100004 name="nostring" type="err" cat="ref"/>
<100005 name="noobj" type="err" cat="ref"/>
</table>
I want to have QList of all names of the child elements (100000 - 100005), but nit the attribute values.
This is my code so far:
QList<QString> xmlActions::GetXMLID (QFile *XMLIndex)
{
QList<QString> xList;
if (XMLIndex->open(QIODevice::ReadOnly))
{
QXmlStreamReader reader (XMLIndex->readAll());
XMLIndex->close();
while(!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType token = reader.readNext();
if(token == QXmlStreamReader::StartElement)
{
if(reader.name().toString() == QLatin1String("table"))
{
continue;
}
xList << reader.name().toString();
}
}
}
return xList;
}
I only get an empy list. If I comment out this:
if(reader.name().toString() == QLatin1String("table"))
{
continue;
}
the only thing that the list contains is 'table' (The start element). I guess this may be quite simple, but I don't get it.