Use xmlbuilder

This uses a full xmlbuilder library - the string building approach started falling down when I used fancy unicode characters.