(in-package :xml) (lisp:clines "#include \"expat-sex.c\"") (lisp:defentry %parse-xml (lisp:object lisp:object) (lisp:object "parse_xml_to_sexp")) (defun read-xml (pathname &optional (trim t)) (whereas ((list (%parse-xml (namestring pathname) t))) (if trim (post-process-xml list) list))) (defun read-xml-from-string (string &optional (trim t)) (whereas ((list (%parse-xml string nil))) (if trim (post-process-xml list) list))) (defun post-process-xml (cons) (let ((car (car cons)) (cdr (cdr cons))) (if (and (stringp car) (stringp cdr)) cons (list* car (collecting (dolist (object cdr) (etypecase object (string (whereas ((string (string-trim-if #'whitespacep object))) (collect string))) (cons (collect (post-process-xml object))))))))))