code: def xmlmetadata(self):
          
          E = ElementMaker(namespace="http://ilk.uvt.nl/folia",nsmap={None: "http://ilk.uvt.nl/folia", 'xml' : "http://www.w3.org/XML/1998/namespace"})
          elements = []
          if self.metadatatype == "native":
              if isinstance(self.metadata, NativeMetaData):
                  for key, value in self.metadata.items():
                      elements.append(E.meta(value,id=key) )
          else:
              if isinstance(self.metadata, ForeignData):
                  #in-document
                  m = self.metadata
                  while m is not None:
                      elements.append(m.xml())
                      m = m.next
          for metadata_id, submetadata in self.submetadata.items():
              subelements = []
              attribs = {
                  "{http://www.w3.org/XML/1998/namespace}id": metadata_id,
                  "type": self.submetadatatype[metadata_id] }
              if isinstance(submetadata, NativeMetaData):
                  for key, value in submetadata.items():
                      subelements.append(E.meta(value,id=key) )
              elif isinstance(submetadata, ExternalMetaData):
                  attribs['src'] = submetadata.url
              elif isinstance(submetadata, ForeignData):
                  #in-document
                  m = submetadata
                  while m is not None:
                      subelements.append(m.xml())
                      m = m.next
              elements.append( E.submetadata(*subelements, **attribs))
          return elements
docs: Internal method to serialize metadata to XML