Xmpppy usage - advanced.

# Introduction

To write a programs using XMPP technology you must understand the basic principles of it. Xmpppy uses it's own implementation of XML handling procedures - so you should get used to it. Though it is simple enough I hope.

Node class

prototype
Node.__init__(name='', attrs={}, payload=[], parent=None, node=None)
Note that 'name' argument really consists of namespace and node name, space separated. Example:
node=Node('jabber:client message', attrs={'to':'target@jid.com'},payload=[Node('body',payload=['Hello target!'])])
or
node=Node('jabber:client message')
node['to']='target@jid.com'
node.NT.body='Hello target!'

NT stands for 'New Tag' and explicitly adds new child to the current node. Also the T can be used. That means "find Tag" but if tag exists it acts just like NT otherwise.
Protocol class
Uses similar syntax. We will use 'node' attribute now:

prototype
Protocol.__init__(name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=None, xmlns='jabber:client', node=None)
example
p=Protocol(node=node)
or
proto=Protocol('message',to='target@jid.com',payload=[Node('body',payload=['Hello target!'])])
or
proto=Protocol('message',to='target@jid.com')
proto.NT.body='Hello target!'

Message class
Similar syntax:

prototype
Message.__init__(to=None, body=None, typ=None, subject=None, attrs={}, frm=None, payload=[], timestamp=None, xmlns='jabber:client', node=None)
example
m=Message(node=proto)
or
m=Message('target@jid.com','Hello target!')

Iq class
Similar syntax:

prototype
Iq.__init__(typ=None, queryNS=None, attrs={}, to=None, frm=None, payload=[], xmlns='jabber:client', node=None)
example
iq=Iq('set',NS_AUTH,payload=[Node('username',payload=['user']),Node('password',payload=['secret'])])
or
iq=Iq('set',NS_AUTH)
iq.T.query.NT.username='user'
iq.T.query.NT.password='secret'
or
iq=Iq('set',NS_AUTH)
iq.T.query.T.username='user'
iq.T.query.T.password='secret'
As I already noted - 'T' acts just like 'NT' if tag doesn't exists.

Presence class
Similar syntax:

prototype
Presence.__init__(to=None, typ=None, priority=None, show=None, status=None, attrs={}, frm=None, timestamp=None, payload=[], xmlns='jabber:client', node=None)
example
pres=Presence(priority=5, show='xa',status="I'm away from my computer")
or
pres=Presence()
pres.setPriority(5) pres.setShow('xa') pres.setStatus("I'm away from my computer") pres.setTimestamp() or
pres=Presence()
pres.T.priority=5 pres.T.show='xa' pres.T.status="I'm away from my computer" pres.setTimestamp()