Where to put formatting
I would add the necessary reformatting of the badly formatted XML to the input processing of the custom module (the one you're writing).

If that is not an option (e.g. if the client insists that the XML feed is saved verbatim), then I would create a custom filter for this content.  Drupal filters do not change the input - it only changes the presentation.