allow encoding to be passed to as_xml