code: def xml_to_str(tree, encoding=None, xml_declaration=False):
      
      if xml_declaration and not encoding:
          raise ValueError("'xml_declaration' is not supported when 'encoding' is None")
      if encoding:
          return tostring(tree, encoding=encoding, xml_declaration=True)
      return tostring(tree, encoding=text_type, xml_declaration=False)
docs: Serialize an XML tree. Returns unicode if 'encoding' is None. Otherwise, we return encoded 'bytes'.