No results with QXmlQuery
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??
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 !
精彩评论