Encode xml on change