docs: def _clean_doc(self, doc=None):
          """Clean the doc before writing it, removing unnecessary properties and doing other operations."""
  
          if doc is None:
              doc = self.doc
  
          resources = doc['Resources']
  
          # We don't need these anymore because all of the data written into the package is normalized.
          for arg in ['startline', 'headerlines', 'encoding']:
              for e in list(resources.args):
                  if e.lower() == arg:
                      resources.args.remove(e)
  
          for term in resources:
              term['startline'] = None
              term['headerlines'] = None
              term['encoding'] = None
  
          schema = doc['Schema']
  
          ## FIXME! This is probably dangerous, because the section args are changing, but the children
          ## are not, so when these two are combined in the Term.properties() acessors, the values are off.
          ## Because of this, _clean_doc should be run immediately before writing the doc.
          for arg in ['altname', 'transform']:
              for e in list(schema.args):
                  if e.lower() == arg:
                      schema.args.remove(e)
  
          for table in self.doc.find('Root.Table'):
              for col in table.find('Column'):
                  try:
                      col.value = col['altname'].value
                  except:
                      pass
  
                  col['altname'] = None
                  col['transform'] = None
  
          # Remove any DSNs
  
          #for dsn_t in self.doc.find('Root.Dsn'):
          #    self.doc.remove_term(dsn_t)
  
  
          return doc