code: def save(self, filename=None):
          
          if not filename:
              filename = self.filename
          if not filename:
              raise Exception("No filename specified")
          if filename[-4:].lower() == '.bz2':
              f = bz2.BZ2File(filename,'wb')
              f.write(self.xmlstring().encode('utf-8'))
              f.close()
          elif filename[-3:].lower() == '.gz':
              f = gzip.GzipFile(filename,'wb') #pylint: disable=redefined-variable-type
              f.write(self.xmlstring().encode('utf-8'))
              f.close()
          else:
              f = io.open(filename,'w',encoding='utf-8')
              f.write(self.xmlstring())
              f.close()
docs: Save the document to file.
  
          Arguments:
              * filename (str): The filename to save to. If not set (``None``, default), saves to the same file as loaded from.