to_xml function (and intermediate functions for all types) implementation.