[Twisted-Python] XmlStream and addObserver - root element's name?

Marcin GliƄski marcin at ascii-art.pl
Wed Dec 17 04:25:10 MST 2008


Hello!

There's a problem I can't find an answer to. I'd like to design Xml
based protocol.
I've found XmlStream, read doc and found addObserver method. I wrote
simple code:

class XmlTest(xmlstream.XmlStream):
    # (...)
    def connectionMade(self):
        xmlstream.XmlStream.connectionMade(self)
        self.addObserver("/frame", self.frameHandler)
        # (...)

    # (...)

    def frameHandler(self, data):
        print "Wilma, I'm Home!"

When I send XML with frame element as a root:

<frame>
 <whatever/>
</frame>

FrameHandler isn't executed, but if I put frame element inside some
other root element:

<sheep>
 <frame>
  <whatever/>
 </frame>
</sheep>

Then my handler is activated. Why? First, I thought maybe my XPath
knowledge is wrong,
so I checked few tutorials[1] and they told me there's something wrong with
addObserver method. How to make it working?



~MG.
(Hi, I'm new here :)




More information about the Twisted-Python mailing list