Generate final xml. Untested