manual xml stream handling, since other methods do not seem to work well