Edited to improve processing (xml needs to be well formed)