Prevent output of control code characters in Views Data Export I've recently experienced a problem where by users have entered control code characters into Long text fields. Specifically the ASCII codes \001, \007, \008, \021 (codes for Start Of Heading, Bell, Backspace, Device control 1) which are causing havoc in my XML exports since they are not allowed by the XML standard and prevent the XML file from being parsed.

Therefore I would like to cleanse the output as it goes through Views Data Export to prevent bad characters from outputting. As commented below, this sounds like a bug in VDE, however I'm wondering whether I can tackle this issue easily with my own views hooks rather than wait for a new version/patch?
Views Data Export enables you to write your own .tpl files for fields. So, in a template for a problematic fields, you might use

preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $input);


to strip all potentially problematic characters. Of course cut list of chars for your specific need and if they are in any way meaningful to your users, consider replacing them with some mark instead of eradicating them entirely. It's a bit clumsy solution, but as far as I remember it works, ant it's fast to get up and running.

You can also use preprocess hook instead of tpl:

/**
 * Implements hook_preprocess_views_view_field().
 */
function mymodule_preprocess_views_view_field(&amp;$vars) {
  if ($vars['view']-&gt;name == 'myview' &amp;&amp; $vars['view']-&gt;plugin_name = 'views_data_export_xml') {
    $vars['output'] = preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $vars['output']);
  }
}