Generate final xml. Fix encoding problems