code: def _loadContext(context, xmlElement, attributeToFormatMap):
      
      attribute = _safeGetRequiredAttribute(xmlElement, 'attribute', '<not set>').lower()
      if attribute != '<not set>':  # there are no attributes for internal contexts, used by rules. See perl.xml
          try:
              format = attributeToFormatMap[attribute]
          except KeyError:
              _logger.warning('Unknown context attribute %s', attribute)
              format = TextFormat()
      else:
          format = None
  
      textType = format.textType if format is not None else ' '
      if format is not None:
          format = _convertFormat(format)
  
      lineEndContextText = xmlElement.attrib.get('lineEndContext', '#stay')
      lineEndContext = _makeContextSwitcher(lineEndContextText,  context.parser)
      lineBeginContextText = xmlElement.attrib.get('lineBeginContext', '#stay')
      lineBeginContext = _makeContextSwitcher(lineBeginContextText, context.parser)
      lineEmptyContextText = xmlElement.attrib.get('lineEmptyContext', '#stay')
      lineEmptyContext = _makeContextSwitcher(lineEmptyContextText, context.parser)
  
      if _parseBoolAttribute(xmlElement.attrib.get('fallthrough', 'false')):
          fallthroughContextText = _safeGetRequiredAttribute(xmlElement, 'fallthroughContext', '#stay')
          fallthroughContext = _makeContextSwitcher(fallthroughContextText, context.parser)
      else:
          fallthroughContext = None
  
      dynamic = _parseBoolAttribute(xmlElement.attrib.get('dynamic', 'false'))
  
      context.setValues(attribute, format, lineEndContext, lineBeginContext, lineEmptyContext, fallthroughContext, dynamic, textType)
  
      # load rules
      rules = _loadChildRules(context, xmlElement, attributeToFormatMap)
      context.setRules(rules)
docs: Construct context from XML element
      Contexts are at first constructed, and only then loaded, because when loading context,
      _makeContextSwitcher must have references to all defined contexts