code: def setdoc(self,newdoc):
          
          self.doc = newdoc
          if self.doc and self.id:
              self.doc.index[self.id] = self
          for c in self:
              if isinstance(c, AbstractElement):
                  c.setdoc(newdoc)
docs: Set a different document. Usually no need to call this directly, invoked implicitly by :meth:`copy`