docs: def parsecommonarguments(object, doc, annotationtype, required, allowed, **kwargs):
      """Internal function to parse common FoLiA attributes and sets up the instance accordingly. Do not invoke directly."""
  
      object.doc = doc #The FoLiA root document
  
      if required is None:
          required = tuple()
      if allowed is None:
          allowed = tuple()
  
      supported = required + allowed
  
  
      if 'generate_id_in' in kwargs:
          try:
              kwargs['id'] = kwargs['generate_id_in'].generate_id(object.__class__)
          except GenerateIDException:
              pass #ID could not be generated, just skip
          del kwargs['generate_id_in']
  
  
  
      if 'id' in kwargs:
          if Attrib.ID not in supported:
              raise ValueError("ID is not supported on " + object.__class__.__name__)
          isncname(kwargs['id'])
          object.id = kwargs['id']
          del kwargs['id']
      elif Attrib.ID in required:
          raise ValueError("ID is required for " + object.__class__.__name__)
      else:
          object.id = None
  
      if 'set' in kwargs:
          if Attrib.CLASS not in supported and not object.SETONLY:
              raise ValueError("Set is not supported on " + object.__class__.__name__)
          if not kwargs['set']:
              object.set ="undefined"
          else:
              object.set = kwargs['set']
          del kwargs['set']
  
          if object.set:
              if doc and (not (annotationtype in doc.annotationdefaults) or not (object.set in doc.annotationdefaults[annotationtype])):
                  if object.set in doc.alias_set:
                      object.set = doc.alias_set[object.set]
                  elif doc.autodeclare:
                      doc.annotations.append( (annotationtype, object.set ) )
                      doc.annotationdefaults[annotationtype] = {object.set: {} }
                  else:
                      raise ValueError("Set '" + object.set + "' is used for " + object.__class__.__name__ + ", but has no declaration!")
      elif annotationtype in doc.annotationdefaults and len(doc.annotationdefaults[annotationtype]) == 1:
          object.set = list(doc.annotationdefaults[annotationtype].keys())[0]
      elif object.ANNOTATIONTYPE == AnnotationType.TEXT:
          object.set = "undefined" #text content needs never be declared (for backward compatibility) and is in set 'undefined'
      elif Attrib.CLASS in required: #or (hasattr(object,'SETONLY') and object.SETONLY):
          raise ValueError("Set is required for " + object.__class__.__name__)
  
  
      if 'class' in kwargs:
          if not Attrib.CLASS in supported:
              raise ValueError("Class is not supported for " + object.__class__.__name__)
          object.cls = kwargs['class']
          del kwargs['class']
      elif 'cls' in kwargs:
          if not Attrib.CLASS in supported:
              raise ValueError("Class is not supported on " + object.__class__.__name__)
          object.cls = kwargs['cls']
          del kwargs['cls']
      elif Attrib.CLASS in required:
          raise ValueError("Class is required for " + object.__class__.__name__)
  
      if object.cls and not object.set:
          if doc and doc.autodeclare:
              if not (annotationtype, 'undefined') in doc.annotations:
                  doc.annotations.append( (annotationtype, 'undefined') )
                  doc.annotationdefaults[annotationtype] = {'undefined': {} }
              object.set = 'undefined'
          else:
              raise ValueError("Set is required for " + object.__class__.__name__ +  ". Class '" + object.cls + "' assigned without set.")
  
  
  
  
  
      if 'annotator' in kwargs:
          if not Attrib.ANNOTATOR in supported:
              raise ValueError("Annotator is not supported for " + object.__class__.__name__)
          object.annotator = kwargs['annotator']
          del kwargs['annotator']
      elif doc and annotationtype in doc.annotationdefaults and object.set in doc.annotationdefaults[annotationtype] and 'annotator' in doc.annotationdefaults[annotationtype][object.set]:
          object.annotator = doc.annotationdefaults[annotationtype][object.set]['annotator']
      elif Attrib.ANNOTATOR in required:
          raise ValueError("Annotator is required for " + object.__class__.__name__)
  
  
      if 'annotatortype' in kwargs:
          if not Attrib.ANNOTATOR in supported:
              raise ValueError("Annotatortype is not supported for " + object.__class__.__name__)
          if kwargs['annotatortype'] == 'auto' or kwargs['annotatortype'] == AnnotatorType.AUTO:
              object.annotatortype = AnnotatorType.AUTO
          elif kwargs['annotatortype'] == 'manual' or kwargs['annotatortype']  == AnnotatorType.MANUAL:
              object.annotatortype = AnnotatorType.MANUAL
          else:
              raise ValueError("annotatortype must be 'auto' or 'manual', got "  + repr(kwargs['annotatortype']))
          del kwargs['annotatortype']
      elif doc and annotationtype in doc.annotationdefaults and object.set in doc.annotationdefaults[annotationtype] and 'annotatortype' in doc.annotationdefaults[annotationtype][object.set]:
          object.annotatortype = doc.annotationdefaults[annotationtype][object.set]['annotatortype']
      elif Attrib.ANNOTATOR in required:
          raise ValueError("Annotatortype is required for " + object.__class__.__name__)
  
      if 'confidence' in kwargs:
          if not Attrib.CONFIDENCE in supported:
              raise ValueError("Confidence is not supported")
          if kwargs['confidence'] is not None:
              try:
                  object.confidence = float(kwargs['confidence'])
                  assert object.confidence >= 0.0 and object.confidence <= 1.0
              except:
                  raise ValueError("Confidence must be a floating point number between 0 and 1, got " + repr(kwargs['confidence']) )
          del kwargs['confidence']
      elif Attrib.CONFIDENCE in required:
          raise ValueError("Confidence is required for " + object.__class__.__name__)
  
  
  
      if 'n' in kwargs:
          if not Attrib.N in supported:
              raise ValueError("N is not supported for " + object.__class__.__name__)
          object.n = kwargs['n']
          del kwargs['n']
      elif Attrib.N in required:
          raise ValueError("N is required for " + object.__class__.__name__)
  
      if 'datetime' in kwargs:
          if not Attrib.DATETIME in supported:
              raise ValueError("Datetime is not supported")
          if isinstance(kwargs['datetime'], datetime):
              object.datetime = kwargs['datetime']
          else:
  
              #try:
              object.datetime = parse_datetime(kwargs['datetime'])
              #except:
              #    raise ValueError("Unable to parse datetime: " + str(repr(kwargs['datetime'])))
          del kwargs['datetime']
      elif doc and annotationtype in doc.annotationdefaults and object.set in doc.annotationdefaults[annotationtype] and 'datetime' in doc.annotationdefaults[annotationtype][object.set]:
          object.datetime = doc.annotationdefaults[annotationtype][object.set]['datetime']
      elif Attrib.DATETIME in required:
          raise ValueError("Datetime is required for " + object.__class__.__name__)
  
      if 'src' in kwargs:
          if not Attrib.SRC in supported:
              raise ValueError("Source is not supported for " + object.__class__.__name__)
          object.src = kwargs['src']
          del kwargs['src']
      elif Attrib.SRC in required:
          raise ValueError("Source is required for " + object.__class__.__name__)
  
      if 'begintime' in kwargs:
          if not Attrib.BEGINTIME in supported:
              raise ValueError("Begintime is not supported for " + object.__class__.__name__)
          object.begintime = parsetime(kwargs['begintime'])
          del kwargs['begintime']
      elif Attrib.BEGINTIME in required:
          raise ValueError("Begintime is required for " + object.__class__.__name__)
  
      if 'endtime' in kwargs:
          if not Attrib.ENDTIME in supported:
              raise ValueError("Endtime is not supported for " + object.__class__.__name__)
          object.endtime = parsetime(kwargs['endtime'])
          del kwargs['endtime']
      elif Attrib.ENDTIME in required:
          raise ValueError("Endtime is required for " + object.__class__.__name__)
  
  
      if 'speaker' in kwargs:
          if not Attrib.SPEAKER in supported:
              raise ValueError("Speaker is not supported for " + object.__class__.__name__)
          object.speaker = kwargs['speaker']
          del kwargs['speaker']
      elif Attrib.SPEAKER in required:
          raise ValueError("Speaker is required for " + object.__class__.__name__)
  
      if 'auth' in kwargs:
          if kwargs['auth'] in ('no','false'):
              object.auth = False
          else:
              object.auth = bool(kwargs['auth'])
          del kwargs['auth']
      else:
          object.auth = object.__class__.AUTH
  
  
  
      if 'text' in kwargs:
          if kwargs['text']:
              object.settext(kwargs['text'])
          del kwargs['text']
  
      if 'phon' in kwargs:
          if kwargs['phon']:
              object.setphon(kwargs['phon'])
          del kwargs['phon']
  
      if 'textclass' in kwargs:
          if not Attrib.TEXTCLASS in supported:
              raise ValueError("Textclass is not supported for " + object.__class__.__name__)
          object.textclass = kwargs['textclass']
          del kwargs['textclass']
      else:
          if Attrib.TEXTCLASS in supported:
              object.textclass = "current"
  
      if 'metadata' in kwargs:
          if not Attrib.METADATA in supported:
              raise ValueError("Metadata is not supported for " + object.__class__.__name__)
          object.metadata = kwargs['metadata']
          if doc:
              try:
                  doc.submetadata[kwargs['metadata']]
              except KeyError:
                  raise KeyError("No such metadata defined: " + kwargs['metadata'])
          del kwargs['metadata']
  
      if object.XLINK:
          if 'href' in kwargs:
              object.href =kwargs['href']
              del kwargs['href']
          if 'xlinktype' in kwargs:
              object.xlinktype = kwargs['xlinktype']
              del kwargs['xlinktype']
          if 'xlinkrole' in kwargs:
              object.xlinkrole = kwargs['xlinkrole']
              del kwargs['xlinkrole']
          if 'xlinklabel' in kwargs:
              object.xlinklabel = kwargs['xlinklabel']
              del kwargs['xlinklabel']
          if 'xlinkshow' in kwargs:
              object.xlinkshow = kwargs['xlinkshow']
              del kwargs['xlinklabel']
          if 'xlinktitle' in kwargs:
              object.xlinktitle = kwargs['xlinktitle']
              del kwargs['xlinktitle']
  
      if doc and doc.debug >= 2:
          print("   @id           = ", repr(object.id),file=stderr)
          print("   @set          = ", repr(object.set),file=stderr)
          print("   @class        = ", repr(object.cls),file=stderr)
          print("   @annotator    = ", repr(object.annotator),file=stderr)
          print("   @annotatortype= ", repr(object.annotatortype),file=stderr)
          print("   @confidence   = ", repr(object.confidence),file=stderr)
          print("   @n            = ", repr(object.n),file=stderr)
          print("   @datetime     = ", repr(object.datetime),file=stderr)
  
  
  
      #set index
      if object.id and doc:
          if object.id in doc.index:
              if doc.debug >= 1: print("[PyNLPl FoLiA DEBUG] Duplicate ID not permitted:" + object.id,file=stderr)
              raise DuplicateIDError("Duplicate ID not permitted: " + object.id)
          else:
              if doc.debug >= 1: print("[PyNLPl FoLiA DEBUG] Adding to index: " + object.id,file=stderr)
              doc.index[object.id] = object
  
      #Parse feature attributes (shortcut for feature specification for some elements)
      for c in object.ACCEPTED_DATA:
          if issubclass(c, Feature):
              if c.SUBSET in kwargs:
                  if kwargs[c.SUBSET]:
                      object.append(c,cls=kwargs[c.SUBSET])
                  del kwargs[c.SUBSET]
  
      return kwargs