Fix an encode problem.

stdout can be in any encoding.

So print encode to that encoding and eventually xmlcharrefreplace if encoding (like ascii) can't encode every unicode char.