Sunday, 19 October 2014

XML / Qt - Can't see attributes when reading with QXmlStreamReader



I have my XML being read properly except for attributes. It is probably a lack of understanding but I can't find the answer. It is my first day using XML, this is my last hurdle.


If I have this in an XML file:



<v location="test">Media Center</v>
<v>Games</v>
<v>Extras</v>
<v>Music</v>
<v>Television</v>


It finds everything but ignores location="test".


This is the code snippet that I am using to try and get 'location'.



else if(section == Section::WrapElements && xml.name().compare("v") == 0)
{
wrapList.append(xml.readElementText());
wrapShortcuts.append(xml.attributes().value("location").toString());
qDebug() << "list: " << wrapList << wrapShortcuts << xml.attributes().count();
continue;
}


wrapList is a QList that stores the names of menu items to later create.


wrapShortcuts is a QList that is trying to store the attribute value.


The debug output of wrapList is as expected (a list containing relevant names).


The debug output of wrapShortcuts is ("", "", "", "", "")


The debug output of xml.attributes().count(); is always 0.


No comments:

Post a Comment