New XML generating code.

This introduces dynamic generation of XML commands so there is
no need for most of the constants at the end of core.py. Adds
a new prettify utility to utils, and fixes a bug in __init__.py
(Exceptions have moved)