It seems that when you write your document you'll have to have settled on UTF-8. You could encode your binary data to be unicode safe and then unescape it afterward. There isn't any "binary-data" character set in XML so the straight write:binary/read:utf8 cycle won't work. You could just toss your XML parser and handle your input yourself.