Bug fix. Catch NPE in the toXml() function. Ticket #NIF-10225