(def xexp (x (o indent 0)) (if acons.x (withs ((tg . lst) x atts nil pad (apply string (n-of indent " ")) pretty (all acons lst)) (and lst (acons caar.lst) (= atts pop.lst)) (string pad "<" tg (tostring:map [pr " " car._ "=\"" cdr._ "\""] atts) ">" (when pretty "\n") (apply string (map [xexp _ (+ indent 3)] lst)) (when pretty pad) "</" tg ">\n")) string.x))
Example:
(xexp '(ying (foo ((bar . baz)) "zing") (yang))) <ying> <foo bar="baz">zing</foo> <yang> </yang> </ying>