Refactor handling of xml declarations