I found so some xml values imported via recv function can have inconsistency between header encoding and used encoding. Internally the header encoding is removed - see xml_out function.
So now, when I have to prepare data for libxml2, I don't do direct cast, but I use xml_out_internal instead. Maybe this technique should be used elsewhere? Same issue I see on xpath function.
Solved issue is not too often probably - the some different encoding than utf8 should be used in XML document and XML document should be loaded with recv function.