isValidXML method re-factored