What I want to do is to react only on specified root elements. For example, if user sends XmlStream that looks like:
<auth> <login>user</login> <pass>dupa.8</pass> </auth>
My method ._auth should be executed. I’ve done it with addObserver method called inside connectionMade method.
self.addObserver('/auth', self._auth)
AFAIK XPath – if I write ‘/auth’ it means that I want my root element to be ‘auth’, so that message:
<longtagislong> <auth>...</auth> </longtagislong>
… should be rejected, because auth isn’t root.
But Twisted however doesn’t work the way I thought it should – my _auth method is executed when second message appears (with auth element inside the tree), not the first one – with auth element as a root.
So, my question is: how to tell Twisted and addObserver method that I want to react only if root element’s name is ‘auth’?
Ok, finally I got the answer. It’s because of XmlStream itself. Connection is active as long as main root element is not closed (for example:
<stream/>). Everything inside it is root element for XPath, that’s why ‘/auth’ means<stream><auth></auth></stream>.