Thanks, Vincent, for sharing your code. Here’s a possible tweak for the first function thats avoids writing files to disk:
declare function local:parse-xml($xml as xs:string) as document-node() { fetch:xml-binary( convert:string-to-base64($xml), map { 'dtd': true() } ) }; The fetch function takes binaries as argument to support encodings different to UTF-8.