Cleaned up export_to_xml function