#10 XDMSerializer escapes already escaped &
I found the problem in changeEntityRef.
I propose to exchange:
val = Utils.replaceAll(val, "&", "&");
with:
val = val.replaceAll( "&(?!(#\\d+;|amp;))", "&");
This worked for my use cases at least fine.
Actually, hexadecimal is also allowed to for the &# expressions.
So:
val = val.replaceAll( "&(?!(#\\d+;|#x[0-9a-fA-F]+;|amp;))", "&");
is better.