Adds proper encoding of XML special characters

Fixes issues with &, <, > etc. in attribute values and elements.