code: def to_sax(walker, handler):
      
      handler.startDocument()
      for prefix, namespace in prefix_mapping.items():
          handler.startPrefixMapping(prefix, namespace)
  
      for token in walker:
          type = token["type"]
          if type == "Doctype":
              continue
          elif type in ("StartTag", "EmptyTag"):
              attrs = AttributesNSImpl(token["data"],
                                       unadjustForeignAttributes)
              handler.startElementNS((token["namespace"], token["name"]),
                                     token["name"],
                                     attrs)
              if type == "EmptyTag":
                  handler.endElementNS((token["namespace"], token["name"]),
                                       token["name"])
          elif type == "EndTag":
              handler.endElementNS((token["namespace"], token["name"]),
                                   token["name"])
          elif type in ("Characters", "SpaceCharacters"):
              handler.characters(token["data"])
          elif type == "Comment":
              pass
          else:
              assert False, "Unknown token type"
  
      for prefix, namespace in prefix_mapping.items():
          handler.endPrefixMapping(prefix)
      handler.endDocument()
docs: Call SAX-like content handler based on treewalker walker
  
      :arg walker: the treewalker to use to walk the tree to convert it
  
      :arg handler: SAX handler to use