title: Escaping control characters in Oracle XDB
body: <p>I'm completely new to Oracle's XDB, in particular using it to generate XML output from a database table, and am working on an application which is moving from 9i (Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production) to 11g (Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production). Here's a small test case which illustrates the problem I'm having:</p>
  
  <pre><code>select xmlelement("test", test) from (select 'a' test from dual);
  </code></pre>
  
  <p>This works and gives me:</p>
  
  <pre><code>&lt;test&gt;a&lt;/test&gt;
  </code></pre>
  
  <p>However in 11g, if I swap 'a' for an invalid character, such as U+0013 I get the following error:</p>
  
  <pre><code>ORA-31061: XDB error: special char to escaped char conversion failed.
  </code></pre>
  
  <p>Under 9i the same thing works successfully, with no error.</p>
  
  <p>Obviously the ideal answer is to have some validation in place to prevent control characters getting into the simple character data that I'm trying to convert into XML, but unfortunately that's outside the scope of what I'm doing.</p>
  
  <p>Is this something anyone else has experienced, and if so, is there a simple change I can make to my XML generating script, or do I need to do some other kind of cleansing? Or just manually fix the problem on the rare occasions that it happens (which would be a perfectly reasonable option for my needs).</p>