PDA

View Full Version : QXmlSerializer, getting attribute and value from serializer



joshz
9th March 2009, 16:17
Hi everyone,
I am using XQuery to grab a node from an XML document, everything works fine up till this point. I don't know what to do next.

Problem description:
I need to grab the attribute and the value from a single node that looks like this


<strong class="class1">0.0376</strong>

to get this node I used


QString xq = "doc('%1')";
QXmlQuery queryxml;
queryxml.setQuery(xq.arg(query));
QByteArray output;
QBuffer buffer(&output);
buffer.open(QIODevice::WriteOnly);

QXmlSerializer serializer(queryxml, &buffer);

if (queryxml.isValid()) {
queryxml.evaluateTo(&serializer);

qDebug() << "output: " << output;
}
The reason I need to get the attribute is that class name will sometimes be "class2" and depending on that I need to do different things with the 0.0376 value.

http://doc.trolltech.com/snapshot/qxmlnodemodelindex.html suggested to use an XML receiver to get attributes, names and child nodes, so I did that, but have no idea how to proceed and haven't seen any examples of this.
So my question is: How to get the attribute and value of the node using either code above or other code that uses XQuery;
Thanks,
josh

ihope
12th August 2009, 00:00
it is easy just put "@" befor name of attribute
like this



QXmlQuery query;
query.setQuery("doc('index.html')/html/body/@onload"); // getting onload event of html document



for value you need

QString QDomElement::text () const