Several bugfixes to work with xml files.
fix to work with xml files