I have prepared an implementation (BSD licensed) of QAbstractXmlNodeModel class from QtXmlPatterns module which makes it possible to run QXmlQuery-ies on a QDomDocument. I've called it QDomNodeModel.
Here's an usage example:
doc.
setContent(QString("<root><elem someAttr='attrValue'><subElem1 /><subElem2 /></elem></root>"),
(QString*) 0,
(int*) 0,
(int*) 0);
QXmlQuery q(QXmlQuery::XQuery10);
QDomNodeModel m(q.namePool(), doc);
q.setFocus(QXmlItem(m.fromDomNode(doc.documentElement())));
q.setQuery("elem/@someAttr");
QXmlResultItems res;
q.evaluateTo(&res);
while (!res.next().isNull())
{
QDomElement elem
= m.
toDomNode(res.
current().
toNodeModelIndex()).
toElement();
qDebug() << m.toDomNode(res.current().toNodeModelIndex()).toAttr().value();
}
QDomDocument doc;
doc.setContent(QString("<root><elem someAttr='attrValue'><subElem1 /><subElem2 /></elem></root>"), (QString*) 0, (int*) 0, (int*) 0);
QXmlQuery q(QXmlQuery::XQuery10);
QDomNodeModel m(q.namePool(), doc);
q.setFocus(QXmlItem(m.fromDomNode(doc.documentElement())));
q.setQuery("elem/@someAttr");
QXmlResultItems res;
q.evaluateTo(&res);
while (!res.next().isNull())
{
QDomElement elem = m.toDomNode(res.current().toNodeModelIndex()).toElement();
qDebug() << m.toDomNode(res.current().toNodeModelIndex()).toAttr().value();
}
To copy to clipboard, switch view to plain text mode
Download link: http://algoholic.eu/wp-content/uploa...demodel.tar.gz
Bookmarks