[Qt-interest] Fwd: How to get XML as evaluation result of a QXmlQuery (XPath)?

Ritter, Nils Nils.Ritter at medizin.uni-leipzig.de
Tue Jul 12 11:31:25 CEST 2011


Hello,

I played around with the  Recipes example project before and had a look into it again yesterday. Maybe I didn't see it, but I can't find code or queries related to my problem.  QXmlFormatter doesn't return the XML but allows for rewriting the result so that it may look like XML. So what I could do is to query the xml file and add all the tags manually back in it.  Also the QXmlFormatter's syntax is a bit unclear. Is there a documentation? For example, what arguments does "string()" take?

I hoped for a way of XML parsing the w3schools example suggests on this website: http://www.w3schools.com/xquery/xquery_example.asp
Easy query, easy XML return value.

Best regards,
Nils

Von: qt-interest-bounces+nils.ritter=medizin.uni-leipzig.de at qt.nokia.com [mailto:qt-interest-bounces+nils.ritter=medizin.uni-leipzig.de at qt.nokia.com] Im Auftrag von Nikos Gerontidis
Gesendet: Montag, 11. Juli 2011 12:01
An: qt-interest at trolltech.com
Betreff: [Qt-interest] Fwd: How to get XML as evaluation result of a QXmlQuery (XPath)?

Hello,

How about the qt example shown in the following link?

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<mailto: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<mailto:qt-interest at qt.nokia.com>" <qt-interest at qt.nokia.com<mailto: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<mailto: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/20110712/186e8483/attachment.html 


More information about the Qt-interest-old mailing list