class Handler(QAbstractMessageHandler):<br>            def handleMessage(self, msg_type, desc, identifier, loc):<br>                print &#39;QUERY:&#39;, msg_type, desc, identifier, loc<br><br>        handler = Handler()<br>
<br>        file_name = &#39;/home/rad/devel/foobar/qt/manager/uis/logic_clientcard.xml&#39;<br><br>        query  = QXmlQuery()<br>        query.setMessageHandler(handler)<br>        query.setQuery(&quot;doc(&#39;%s&#39;)/logic/rule[@name=&#39;test&#39;]&quot; % 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 &#39;result of evaluation is&#39;,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 &#39;not evaluated&#39;</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 &#39;not valid&#39;</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">&lt;<a href="mailto:ruslan.popov@gmail.com">ruslan.popov@gmail.com</a>&gt;</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 = &#39;doc(&quot;/home/rad/project/qt/manager/uis/logic.xml&quot;)/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 &#39;QUERY:&#39;, 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 &lt;html xmlns=&#39;<a href="http://www.w3.org/1999/xhtml/" target="_blank">http://www.w3.org/1999/xhtml/</a>&#39;&gt;&lt;body&gt;&lt;p&gt;syntax error, unexpected &amp;lt;number literal&amp;gt;, expecting )&lt;/p&gt;&lt;/body&gt;&lt;/html&gt; PyQt4.QtCore.QUrl(u&#39;<a href="http://www.w3.org/2005/xqt-errors#XPST0003" target="_blank">http://www.w3.org/2005/xqt-errors#XPST0003</a>&#39;) &lt;PyQt4.QtXmlPatterns.QSourceLocation object at 0x2204120&gt;</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">&lt;<a href="mailto:dboddie@trolltech.com" target="_blank">dboddie@trolltech.com</a>&gt;</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>
&gt; Can someone explain me how to use QXmlQuery. I have simple XML file on the<br>
&gt; filesystem and I need to get one piece of it. My code following:<br>
&gt;<br>
&gt;         out = QString()<br>
&gt;         query  = QXmlQuery()<br>
&gt;         query.setMessageHandler(handler)<br>
&gt;         q_str = &#39;doc(&quot;./uis/logic.xml&quot;)/logic/rule&#39;<br>
&gt;         query.setQuery(q_str)<br>
<br>
</div>Have you tried using an absolute path instead of &quot;./uis/logic.xml&quot;?<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>