Big work in progress: xml
Preliminary write - needs bugtesting