class Handler(QAbstractMessageHandler):<br> def handleMessage(self, msg_type, desc, identifier, loc):<br> print 'QUERY:', msg_type, desc, identifier, loc<br><br> handler = Handler()<br>
<br> file_name = '/home/rad/devel/foobar/qt/manager/uis/logic_clientcard.xml'<br><br> query = QXmlQuery()<br> query.setMessageHandler(handler)<br> query.setQuery("doc('%s')/logic/rule[@name='test']" % file_name )<br>
Thanks goes to <a href="http://old.nabble.com/QXmlQuery.evaluate%28%29-does%27nt-accept-QString-parameter--td28002664.html">http://old.nabble.com/QXmlQuery.evaluate%28%29-does%27nt-accept-QString-parameter--td28002664.html</a><br>
<br>The working code is:<br><br><span style="font-family: courier new,monospace;"> array = QByteArray()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> buf = QBuffer(array)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> buf.open(QIODevice.WriteOnly)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if query.isValid():</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if query.evaluateTo(buf):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> results = QString.fromUtf8(array)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print 'result of evaluation is',results</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> else:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print 'not evaluated'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> else:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print 'not valid'</span><br style="font-family: courier new,monospace;"><br><br><div class="gmail_quote">On Wed, Jun 23, 2010 at 1:21 AM, Ruslan Popov <span dir="ltr"><<a href="mailto:ruslan.popov@gmail.com">ruslan.popov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I have tried right now:<br><br><span style="font-family: courier new,monospace;">q_str = 'doc("/home/rad/project/qt/manager/uis/logic.xml")/logic/rule</span><br style="font-family: courier new,monospace;">
<div style="font-family: courier new,monospace;">
query.setQuery(q_str)</div><br>also I have handler like this:<br><br><span style="font-family: courier new,monospace;">class Handler(QAbstractMessageHandler):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> def handleMessage(self, msg_type, desc, identifier, loc):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print 'QUERY:', msg_type, desc, identifier, loc</span><br style="font-family: courier new,monospace;"><br>and it responds this time:<br><br><span style="font-family: courier new,monospace;">QUERY: 3 <html xmlns='<a href="http://www.w3.org/1999/xhtml/" target="_blank">http://www.w3.org/1999/xhtml/</a>'><body><p>syntax error, unexpected &lt;number literal&gt;, expecting )</p></body></html> PyQt4.QtCore.QUrl(u'<a href="http://www.w3.org/2005/xqt-errors#XPST0003" target="_blank">http://www.w3.org/2005/xqt-errors#XPST0003</a>') <PyQt4.QtXmlPatterns.QSourceLocation object at 0x2204120></span><div>
<div></div><div class="h5"><br style="font-family: courier new,monospace;">
<br><br><div class="gmail_quote">On Tue, Jun 22, 2010 at 8:38 PM, David Boddie <span dir="ltr"><<a href="mailto:dboddie@trolltech.com" target="_blank">dboddie@trolltech.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>On Tue Jun 22 07:03:51 BST 2010, Ruslan Popov wrote:<br>
<br>
> Can someone explain me how to use QXmlQuery. I have simple XML file on the<br>
> filesystem and I need to get one piece of it. My code following:<br>
><br>
> out = QString()<br>
> query = QXmlQuery()<br>
> query.setMessageHandler(handler)<br>
> q_str = 'doc("./uis/logic.xml")/logic/rule'<br>
> query.setQuery(q_str)<br>
<br>
</div>Have you tried using an absolute path instead of "./uis/logic.xml"?<br>
<font color="#888888"><br>
David<br>
</font><div><div></div><div>_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div><div><div></div><div class="h5">-- <br>Ruslan Popov<br>phone: +7 916 926 1205<br><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Ruslan Popov<br>phone: +7 916 926 1205<br><br>