code: def internal_to_elem(pfsh, factory=ET.Element):
  
      
  
      attribs = {}
      text = None
      tail = None
      sublist = []
      tag = list(pfsh.keys())
      if len(tag) != 1:
          raise ValueError("Illegal structure with multiple tags: %s" % tag)
      tag = tag[0]
      value = pfsh[tag]
      if isinstance(value, dict):
          for k, v in list(value.items()):
              if k[:1] == "@":
                  attribs[k[1:]] = v
              elif k == "#text":
                  text = v
              elif k == "#tail":
                  tail = v
              elif isinstance(v, list):
                  for v2 in v:
                      sublist.append(internal_to_elem({k: v2}, factory=factory))
              else:
                  sublist.append(internal_to_elem({k: v}, factory=factory))
      else:
          text = value
      e = factory(tag, attribs)
      for sub in sublist:
          e.append(sub)
      e.text = text
      e.tail = tail
      return e
docs: Convert an internal dictionary (not JSON!) into an Element.
  
      Whatever Element implementation we could import will be
      used by default; if you want to use something else, pass the
      Element class as the factory parameter.