Test XML processing

... and some related changes (and bugfixes) in the main code.