tags:

views:

229

answers:

1

I'm getting really fustrated with this...

With this simple xml:

<?xml version='1.0'?>
<root>
   <data>hello</data>
</root>

And this code

QXmlQuery xquery;
xquery.setQuery( "doc('config.xml')//data" );

if( xquery.isValid() )
{
    QXmlResultItems itemResult;
 xquery.evaluateTo( &itemResult );
 QXmlItem item( itemResult.next() );
 while( !item.isNull() )
 {
  QVariant value = item.toAtomicValue();
  qDebug() << "One XML result!!!";
  item = itemResult.next();
 }
}

This code simply doesn't throw me any results. I've checked that the execute path of app is the same where the config.xml is located.

Official documentation doesn't help me very much and seems there's no extra info on internet about details on how to use this class.

I have another program that successfully loads data from an xml and the code is exactly like the posted one. Even throws me an error if xml file is not found (a thing that with my current app doesn't happens).

Of course I'm configuring the .pro file to use xmlpatterns:

QT += xmlpatterns

Any clue??

+1  A: 

Hey,

I remember I had some trouble with it as well... Anyway, I've found that I was using the following lines :

QFile SourceDocument;
SourceDocument.setFileName(rXmlFilePath);
...
Query.bindVariable("inputDocument", &SourceDocument);
QString FinalQuery("declare variable $inputDocument external;doc($inputDocument)//chapter");
Query.setQuery(FinalQuery);

I hope it will help you a bit !

Andy M