Cleaned up code for saving an XML file to make it more generic.