QtXmlPatterns using QXmlItem to focus in QXmlQuery cannot get results.
-
wrote on 15 Mar 2013, 14:41 last edited by
Hi all,
I try to query a node say the following :"/TestRun/Config/Test/PA/Pulse" with the code bellow:
@ QFile* file = new QFile("/home/user/hardwaretest.xml");
qDebug() << file->open(QIODevice::ReadOnly);QXmlQuery query; query.setFocus(file); query.setQuery("/TestRun/Config/Test/PA/Pulse"); QXmlResultItems* results = new QXmlResultItems(); query.evaluateTo(results); QXmlItem item = results->next(); while(!item.isNull()) { if(item.isNode()) { QXmlQuery query2; query2.setFocus(item); query2.setQuery("./@pulseWidth/string()"); QXmlResultItems* results2 = new QXmlResultItems(); query2.evaluateTo(&results2); QXmlItem item2 = results2->next(); while(!item2.isNull()) { if(item2.isAtomicValue()) qDebug() << item2.toAtomicValue().toString(); if(item2.isNode()) qDebug() << "item2 is a node"; item2 = results2->next(); } delete results2; } item = results->next(); } file->close(); delete file; delete results;@
Here is a part of my xml file :
@<?xml version="1.0" encoding="UTF-8"?>
<TestRun>
<Config>
<Test name="Pulser">
<PA>
<!-- amplitude % - pulseWidth % - riseTime V/ns - reverberation % -->
<Pulse amplitude="0.1" pulseWidth="0.1" riseTime="10" reverberation="0.04" />
</PA>
<UT>
<!-- amplitude % - pulseWidth % - riseTime V/ns - reverberation % -->
<Pulse amplitude="0.1" pulseWidth="0.1" riseTime="10" reverberation="0.04" />
</UT>
</Test>
<TestRun>@I do get the node
@<Pulse amplitude="0.1" pulseWidth="0.1" riseTime="10" reverberation="0.04" />@on the first query, but the second only return an empty node...
I never were able to get results with QXmlQuery focused on an QXmlItem.
Somebody knows what I do wrong here?
Thank in advance. -
wrote on 25 Nov 2014, 01:51 last edited by
Figured out how to do such things. One can view the solution "here":http://stackoverflow.com/a/27117841/694123.
-
wrote on 25 Nov 2014, 01:51 last edited byThis post is deleted!