[PyQt] QXmlQuery example needed - SOLVED
Ruslan Popov
ruslan.popov at gmail.com
Wed Jun 23 20:55:57 BST 2010
class Handler(QAbstractMessageHandler):
def handleMessage(self, msg_type, desc, identifier, loc):
print 'QUERY:', msg_type, desc, identifier, loc
handler = Handler()
file_name =
'/home/rad/devel/foobar/qt/manager/uis/logic_clientcard.xml'
query = QXmlQuery()
query.setMessageHandler(handler)
query.setQuery("doc('%s')/logic/rule[@name='test']" % file_name )
Thanks goes to
http://old.nabble.com/QXmlQuery.evaluate%28%29-does%27nt-accept-QString-parameter--td28002664.html
The working code is:
array = QByteArray()
buf = QBuffer(array)
buf.open(QIODevice.WriteOnly)
if query.isValid():
if query.evaluateTo(buf):
results = QString.fromUtf8(array)
print 'result of evaluation is',results
else:
print 'not evaluated'
else:
print 'not valid'
On Wed, Jun 23, 2010 at 1:21 AM, Ruslan Popov <ruslan.popov at gmail.com>wrote:
> I have tried right now:
>
> q_str = 'doc("/home/rad/project/qt/manager/uis/logic.xml")/logic/rule
> query.setQuery(q_str)
>
> also I have handler like this:
>
> class Handler(QAbstractMessageHandler):
> def handleMessage(self, msg_type, desc, identifier, loc):
> print 'QUERY:', msg_type, desc, identifier, loc
>
> and it responds this time:
>
> QUERY: 3 <html xmlns='http://www.w3.org/1999/xhtml/'><body><p>syntax
> error, unexpected <number literal>, expecting )</p></body></html>
> PyQt4.QtCore.QUrl(u'http://www.w3.org/2005/xqt-errors#XPST0003')
> <PyQt4.QtXmlPatterns.QSourceLocation object at 0x2204120>
>
>
>
> On Tue, Jun 22, 2010 at 8:38 PM, David Boddie <dboddie at trolltech.com>wrote:
>
>> On Tue Jun 22 07:03:51 BST 2010, Ruslan Popov wrote:
>>
>> > Can someone explain me how to use QXmlQuery. I have simple XML file on
>> the
>> > filesystem and I need to get one piece of it. My code following:
>> >
>> > out = QString()
>> > query = QXmlQuery()
>> > query.setMessageHandler(handler)
>> > q_str = 'doc("./uis/logic.xml")/logic/rule'
>> > query.setQuery(q_str)
>>
>> Have you tried using an absolute path instead of "./uis/logic.xml"?
>>
>> David
>> _______________________________________________
>> PyQt mailing list PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
>
>
> --
> Ruslan Popov
> phone: +7 916 926 1205
>
>
--
Ruslan Popov
phone: +7 916 926 1205
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100623/a0f77844/attachment.html>
More information about the PyQt
mailing list