code: def get_ligolw_element(xmldoc):
      
      from ligo.lw.ligolw import LIGO_LW
      try:
          from glue.ligolw.ligolw import LIGO_LW as LIGO_LW2
      except ImportError:
          ligolw_types = (LIGO_LW,)
      else:
          ligolw_types = (LIGO_LW, LIGO_LW2)
  
      if isinstance(xmldoc, ligolw_types):
          return xmldoc
      else:
          for node in xmldoc.childNodes:
              if isinstance(node, ligolw_types):
                  return node
      raise ValueError("Cannot find LIGO_LW element in XML Document")
docs: Find an existing <LIGO_LW> element in this XML Document