[Twisted-Python] Help using XmlStreamFactory & XmlStream : XPathQuery error?

Gabriel Rossetti mailing_lists at evotex.ch
Tue Feb 19 06:29:38 EST 2008

Gabriel Rossetti wrote:
> Hello,
> I am trying to write a Server and Client that use an XML protocol. I 
> saw that there is a XmlStream class and tried to use it, but was 
> unable to. I saw one small example for a client 
> (http://ralphm.net/blog/2005/10), but it raises some questions.
> First of all, it seams to work compleatly differently that the other 
> server/client examples.
> I don't understand why there is a need to add observers, and what they 
> are used for. I can't get any of these to work (on either side, client 
> or server):
>    def connectionMade(self):
>        print 'Connected!'
>    def dataReceived(self, data):
>        print data
>    def onDocumentStart(self, rootElement):
>        print "Message start : ", rootElement
>    def onElement(self, element):
>        print "current element : ", element
>    def onDocumentEnd(self, rootElement):
>        print "Message end : ", rootElement
> I'm kind of lost :-(
> I'm new to Twisted and I though that I understood how it works (read 
> howtos, turorials, etc, but this one doesn't seam like the others. Can 
> someone please point me to an example, I searched google but no luck. 
> All I need is a simple client-server xml echo example or a better 
> understanding of how it works and how it differs from the other echo 
> examples. Thank you,
> Gabriel
> Thank you
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Ok, I've got some code sort of working, if I use the following 
XPathQuery string : "/*" on the following XML string :

<?xml version="1.0" encoding="utf-8"?>
<test><feed name="test">toto</feed></test>

the addObserver works ( xs.addObserver("/*", self.onTest) )
 but if I try the following :

xs.addObserver("/test/feed/@name", self.onTest)
xs.addObserver(xpath.XPathQuery("/test/feed/@name"), self.onTest)

I get the following :

"/usr/lib/python2.5/site-packages/twisted/words/xish/xmlstream.py", line 
104, in onElement
  File "/usr/lib/python2.5/site-packages/twisted/words/xish/utility.py", 
line 232, in dispatch
    if query.matches(object):
  File "/usr/lib/python2.5/site-packages/twisted/words/xish/xpath.py", 
line 238, in matches
    return self.baseLocation.matches(elem)
exceptions.AttributeError: 'NoneType' object has no attribute 'matches'

Does anyone understand why?

More information about the Twisted-Python mailing list