Added escaping of XML entities.
Updated tests.