XML IO: allow custom element classes.
Move some common stuff from plugins into `xmpp`.
Improve error handling, add some docstrings.