docs: def untlpy2etd_ms(untl_elements, **kwargs):
      """Convert the UNTL elements structure into an ETD_MS structure.
  
      kwargs can be passed to the function for certain effects.
      """
      degree_children = {}
      date_exists = False
      seen_creation = False
      # Make the root element.
      etd_ms_root = ETD_MS_CONVERSION_DISPATCH['thesis']()
      for element in untl_elements.children:
          etd_ms_element = None
          # Convert the UNTL element to etd_ms where applicable.
          if element.tag in ETD_MS_CONVERSION_DISPATCH:
              # Create the etd_ms_element if the element's content
              # is stored in children nodes.
              if element.children:
                  etd_ms_element = ETD_MS_CONVERSION_DISPATCH[element.tag](
                      qualifier=element.qualifier,
                      children=element.children,
                  )
              # If we hit a degree element, make just that one.
              elif element.tag == 'degree':
                  # Make a dict of the degree children information.
                  if element.qualifier in ['name',
                                           'level',
                                           'discipline',
                                           'grantor']:
                      degree_children[element.qualifier] = element.content
              # For date elements, limit to first instance of creation date.
              elif element.tag == 'date':
                  if element.qualifier == 'creation':
                      # If the root already has a date, delete the child.
                      for child in etd_ms_root.children:
                          if child.tag == 'date':
                              del child
                              if not seen_creation:
                                  date_exists = False
                      seen_creation = True
                      if not date_exists:
                          # Create the etd_ms element.
                          etd_ms_element = ETD_MS_CONVERSION_DISPATCH[element.tag](
                              qualifier=element.qualifier,
                              content=element.content,
                          )
                          date_exists = True
              # It is a normal element.
              elif element.tag not in ['date', 'degree']:
                  # Create the etd_ms_element.
                  etd_ms_element = ETD_MS_CONVERSION_DISPATCH[element.tag](
                      qualifier=element.qualifier,
                      content=element.content,
                  )
              # Add the element to the structure if the element exists.
              if etd_ms_element:
                  etd_ms_root.add_child(etd_ms_element)
          if element.tag == 'meta':
              # Initialize ark to False because it may not exist yet.
              ark = False
              # Iterate through children and look for ark.
              for i in etd_ms_root.children:
                  if i.tag == 'identifier' and i.content.startswith(
                      'http://digital.library.unt.edu/'
                  ):
                      ark = True
              # If the ark doesn't yet exist, try and create it.
              if not ark:
                  # Reset for future tests.
                  ark = False
                  if element.qualifier == 'ark':
                      ark = element.content
                  if ark is not None:
                      # Create the ark identifier element and add it.
                      ark_identifier = ETD_MS_CONVERSION_DISPATCH['identifier'](
                          ark=ark,
                      )
                      etd_ms_root.add_child(ark_identifier)
      # If children exist for the degree, make a degree element.
      if degree_children:
          degree_element = ETD_MS_CONVERSION_DISPATCH['degree']()
          # When we have all the elements stored, add the children to the
          # degree node.
          degree_child_element = None
          for k, v in degree_children.iteritems():
              # Create the individual classes for degrees.
              degree_child_element = ETD_MS_DEGREE_DISPATCH[k](
                  content=v,
              )
              # If the keys in degree_children are valid,
              # add it to the child.
              if degree_child_element:
                  degree_element.add_child(degree_child_element)
          etd_ms_root.add_child(degree_element)
      return etd_ms_root