[Qt-interest] Question efficient use of QXmlQuery
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Wed Sep 22 06:55:16 CEST 2010
I have a project that that is downloading an XML file, and running an
QXmlQuery on file to reduce the data using QAbstractXmlReceiver derived
class...
The XQuery uses a bound variable $xmlDoc, which is set using
query.bindVariable tied to a QBuffer.
Everything works...
However, In reading the QXmlQuery docs in further detail, I found this
little note
"When setQuery() is called, the query text is compiled into an internal
data structure and optimized. The optimized form can then be reused for
multiple evaluations of the query. Since the compile-and-optimize
process can be expensive, repeating it for the same query should be
avoided by using a separate instance of QXmlQuery for each query text."
Implying you should set the query once, and then set the XML data over
and over again...
My question.. How???
Here is my code, xml is a sent in QString download from multiple
different locations... CReciever is a QAbstractXmlReceiver derived
class...
static char * sQueryText =
"for $item in doc($xmlDoc)/*/*/*:Item\n"
"return <Item>\n"
"{\n"
"<Author>{fn:data($item/*:ItemAttributes/*:Author)}</Author>\n"
"}\n"
"</Item>"
;
QBuffer xmlBuffer;
xmlBuffer.setData( xml.toUtf8() );
xmlBuffer.open( QIODevice::ReadOnly );
QXmlQuery query;
query.bindVariable("xmlDoc", &xmlBuffer);
query.setQuery( sQueryTxt );
CReceiver receiver( query.namePool() );
QString tmp;
if ( !query.evaluateTo( &receiver ) )
.....
Any ideas would be appreciated... If I call bindVariable after the
setQuery, it fails since the query text has a reference to the
variable...
Thanks in advance
Scott
More information about the Qt-interest-old
mailing list