added error handling if trying to toxml on null value fields