code: def open_xmldoc(fobj, **kwargs):
      
      from ligo.lw.ligolw import (Document, LIGOLWContentHandler)
      from ligo.lw.lsctables import use_in
      from ligo.lw.utils import (load_filename, load_fileobj)
  
      use_in(kwargs.setdefault('contenthandler', LIGOLWContentHandler))
  
      try:  # try and load existing file
          if isinstance(fobj, string_types):
              return load_filename(fobj, **kwargs)
          if isinstance(fobj, FILE_LIKE):
              return load_fileobj(fobj, **kwargs)[0]
      except (OSError, IOError):  # or just create a new Document
          return Document()
      except LigolwElementError as exc:
          if LIGO_LW_COMPAT_ERROR.search(str(exc)):
              try:
                  return open_xmldoc(fobj, ilwdchar_compat=True, **kwargs)
              except Exception:  # for any reason, raise original
                  pass
          raise
docs: Try and open an existing LIGO_LW-format file, or create a new Document
  
      Parameters
      ----------
      fobj : `str`, `file`
          file path or open file object to read
  
      **kwargs
          other keyword arguments to pass to
          :func:`~ligo.lw.utils.load_filename`, or
          :func:`~ligo.lw.utils.load_fileobj` as appropriate
  
      Returns
      --------
      xmldoc : :class:`~ligo.lw.ligolw.Document`
          either the `Document` as parsed from an existing file, or a new, empty
          `Document`