code: def pydict2xml(filename, metadata_dict, **kwargs):
      
      try:
          f = open(filename, 'w')
          f.write(pydict2xmlstring(metadata_dict, **kwargs).encode('utf-8'))
          f.close()
      except:
          raise MetadataGeneratorException(
              'Failed to create an XML file. Filename: %s' % (filename)
          )
docs: Create an XML file.
  
      Takes a path to where the XML file should be created
      and a metadata dictionary.