code: def setdocument(self, doc):
          
          assert isinstance(doc, Document)
  
          if not self.doc:
              self.doc = doc
              if self.id:
                  if self.id in doc:
                      raise DuplicateIDError(self.id)
                  else:
                      self.doc.index[id] = self
  
          for e in self: #recursive for all children
              if isinstance(e,AbstractElement): e.setdocument(doc)
docs: Associate a document with this element.
  
          Arguments:
              doc (:class:`Document`): A document
  
          Each element must be associated with a FoLiA document.