>Unless your file is absolutely massive, FILETOSTR() and a string insertion is going to be blazing fast - this is not something you should worry about unless you have multi-megabyte file that exceeds 16 megs. In that case you have to be careful as you won't be able to simply concat the header and footer to the string (you'd have to write out file as stream).
But then an XML of that size would be unwieldy in any context, and may break something even if it was syntactically perfect.
>What's more concerning though is - why is the data you are receiving invalid, non-parsable XML in the first place?
You wouldn't believe what's out there (except you've been out there and seen even more crap than I did). I had to handle a headerless xml, with numerous inconsistencies in naming but generously peppered with sixtuple line breaks - from a company whose worth is in dozens of millions and whose main reason to exist is exchange and aggregation of information and then passing the processed and validated data further down the chain. IOW, a professional intermediary makes millions passing xml back and forth - and still can't get around to have a header in it. Luckily, MS Xml parser doesn't care, reads it fine.