Hey @all,
i want to make some steps with the QXmlQuery. Could anybody help me because in the Documentation of the QXmlQuery there aren't many examples.
<document>
<units name="Measures">
<unit name="Meter">m</unit>
<unit name="Centimeter">cm</unit>
<unit name="Millimeter">mm</unit>
</units>
</document>
<document>
<units name="Measures">
<unit name="Meter">m</unit>
<unit name="Centimeter">cm</unit>
<unit name="Millimeter">mm</unit>
</units>
</document>
To copy to clipboard, switch view to plain text mode
So, for the example normally i iterate over the nodes, but i think this is a good example where i can practice QXmlQuery. I want the units name, and then the unit names and there values.
Currently I have the following to get the values of the units, but how can i get the attribute names and there values?
QXmlQuery query;
query.
setQuery(QString("doc('%0')/document/units/unit/text()").
arg(filename
));
QXmlSerializer serializer(query, &buffer);
bool ret = query.evaluateTo(&serializer);
qDebug() << "XmlQuery Ret: " << ret;
qDebug() << "XmlQuery Results: " << source;
QString filename = "test.xml";
QXmlQuery query;
QByteArray byteArray;
QBuffer buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
query.setQuery(QString("doc('%0')/document/units/unit/text()").arg(filename));
QXmlSerializer serializer(query, &buffer);
bool ret = query.evaluateTo(&serializer);
QString source = QString(byteArray);
qDebug() << "XmlQuery Ret: " << ret;
qDebug() << "XmlQuery Results: " << source;
To copy to clipboard, switch view to plain text mode
I also noticed that xml query can be made with some sort of "SELECT * FROM ...", but how can I use them with QXmlQuery and I also don't know if there is a way to get a list of QDomNodes as results.
Regards
Bookmarks