Hello Hans-Jürgen,
To detect if a file starts with a BOM, you can use the following
code:
let $file := 'some-file.xml'
let $bytes := array { $file => file:read-binary(0, 4) =>
bin:to-octets() }
let $boms := (
(: UTF-8 :) [0xef, 0xbb, 0xbf],
(: UTF-16LE :) [0xfe, 0xff],
(: UTF-16BE :) [0xff, 0xfe],
(: UTF-32BE BOM :) [0x00, 0x00, 0xfe, 0xff],
(: UTF-32LE BOM :) [0xff, 0xfe, 0x00, 0x00]
)
return some $bom in $boms satisfies
deep-equal(array:subarray($bytes, 1, array:size($bom)), $bom)
But I would have suspected that fn:doc would be okay with XML
files including a BOM, since those are legal XML files as far as I
remember.
Greetings,
Hauke