REF: Deduplicate to_xml code
- [x] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit) for how to run them

This also fixes some typing bugs detected after removing the _init_ implementation
LGTM! Thanks, @phofl. Be sure to rebase. thanks @phofl and @ParfaitG for reviewing