If you use the XOG query api you might be able to create an output file which is close to be used as the input file.
There is a little you need to do more to the that before you use it as in the input like putting the header and the footer and maybe some editing.
That was slightly touched in
How to XOG out (read) resource using filter for Termination Date attribute
98362667
and there is a reference to examples using the query api in that thread.
Martti K.