PDA

View Full Version : Help needed with QXmlQuery



NoRulez
7th November 2008, 09:52
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>

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?


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;

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

Kumosan
7th November 2008, 12:25
I also don't know if there is a way to get a list of QDomNodes as results.


Now you know: There isn't.