[encode_test] Make the encode tests more pleasant.
Kill all the internal error returns and prefer panic/recover.
[encode_test] Lift out common XML preamble junk.