[Qt-interest] Fwd: How to get XML as evaluation result of a QXmlQuery (XPath)?
Nikos Gerontidis
geronik444 at gmail.com
Mon Jul 11 12:00:54 CEST 2011
Hello,
How about the qt example shown in the following link?
http://doc.qt.nokia.com/4.7-snapshot/xmlpatterns-recipes.html
<http://doc.qt.nokia.com/4.7-snapshot/xmlpatterns-recipes.html>I hope that
helps.
---------- Forwarded message ----------
From: Ritter, Nils <Nils.Ritter at medizin.uni-leipzig.de>
Date: Mon, Jul 11, 2011 at 12:30 PM
Subject: [Qt-interest] How to get XML as evaluation result of a QXmlQuery
(XPath)?
To: "qt-interest at qt.nokia.com" <qt-interest at qt.nokia.com>
Hello,****
I’m trying to query a XML file with QXmlQuery and XPath. Due to the
structure of the XML it would be nice to get the result of the query as
another XML string for further querying. My example XML string looks like
this:****
** **
<legs>****
<left>****
<leg>****
<name>Name1</name>****
</leg>****
<leg>****
<name>Name2</name>****
</leg>****
<leg>****
<name>Name3</name>****
</leg>****
</left>****
</legs>****
** **
The code to access the XML:****
QCoreApplication a(argc, argv);****
QString xml =
"<legs><left><leg><name>Name1</name></leg><leg><name>Name1</name></leg>\****
<leg><name>Name1</name></leg></left></legs>";
****
QBuffer device;****
device.setData(xml.toUtf8());****
device.open(QIODevice::ReadOnly);****
QXmlQuery query;****
query.bindVariable("inputDocument", &device);
query.setQuery("doc($inputDocument)/legs/left/node()");****
if (query.isValid()) {****
QStringList sl;****
query.evaluateTo(&sl);****
for (QStringList::iterator it = sl.begin(); it != sl.end(); ++it)****
qDebug() << *it;****
} else****
qDebug() << "query invalid";****
** **
I tried several queries to access the XML of one leg:****
/legs/left/node() returns empty string list****
/legs/left/node()/string() returns three strings “Name1”,”Name2”, “Name3”
without any tags /legs/left return empty string list****
/legs/left/string() returns just 3 strings containing “Name1”,”Name2”,
“Name3”****
** **
Is it possible to get XML as result of a QXmlQuery? If so, does work with
evaluation to QStringList or are other structures necessary?****
** **
Thanks in advance.****
** **
-Nils****
** **
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
--
Best Regards
Nikos Gerontidis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110711/2f754e95/attachment.html
More information about the Qt-interest-old
mailing list