The new XML services code

I have now incorporated everyone's comments (I think), except that I have left in doctests within the docstrings for the moment whilst Kenneth and Stefan decide whether they want them or not! This PR is rebased onto master, with all the various commits squashed as far as possible.  NB this particular PR does not affect the core.py at all. The changes to core will be in a separate PR.

As far as I can tell, it is ready to commit