import re


def ElementToComplexType(xsd):
  """Replaces the first <element> tag with the complexType inside of it.

  The complexType tag will use the name attribute from the removed element tag.

  Args:
    xsd: str XSD string contents.

  Returns:
    str: Modified XSD.
  """
  xsd = re.sub(r'<(\w+:)?element name="(\w+)">\s*<(\w+:)?complexType>',
               '<\\3complexType name="\\2">',
               xsd)
  xsd = re.sub(r'(\s+)?</(\w+:)?element>', '', xsd)
  xsd = re.sub(r'<\?xml.*?>', '', xsd)
  return xsd