Fixes coding of input and some bugs
write_xml method with unicode support.