Postgres: turn off formating for xml export?
The psql command \? shows the option to turn off expanded formatting:

Formatting:
...
  \x [on|off|auto]       toggle expanded output (currently off)


Typically it will show table data in one record per line if its "off" or else each field in its own line when switched on, e.g.:

postgres=# \x off
Expanded display is off.
postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | en_IN   | en_IN |


When its switched on:

postgres=# \x on
Expanded display is on.
postgres=# \l
List of databases
-[ RECORD 1 ]-----+----------------------
Name              | postgres
Owner             | postgres
Encoding          | UTF8
Collate           | en_IN
Ctype             | en_IN
Access privileges |
-[ RECORD 2 ]-----+----------------------


With xml output, since everything is in one stream, it shows the record label before printing out the xml.
The difference between /x on and /x off is as follows:

/x on

table_to_xml|&lt;pg_attribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;attrelid&gt;1255&lt;/attrelid&gt;
  &lt;attname&gt;proname&lt;/attname&gt;
  &lt;atttypid&gt;19&lt;/atttypid&gt;
  &lt;attstattarget&gt;-1&lt;/attstattarget&gt;


With /x off the output is:

/x off
&lt;pg_attribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;attrelid&gt;1255&lt;/attrelid&gt;
  &lt;attname&gt;proname&lt;/attname&gt;
  &lt;atttypid&gt;19&lt;/atttypid&gt;
  &lt;attstattarget&gt;-1&lt;/attstattarget&gt;


So before writing to the file you should change the commands issued as follows:

\t on
\x off
\pset format unaligned