Move xml-specific functionality into xml module, add unittest.