title: JAXB / Java 1.6 / Non-printable characters
body: <p><strong>Background</strong>: I'm reading a file structure on different old OS (Aix, HP-UX...) and turn some path- and file-information into an XML document.</p>
  
  <p>Problem: Sometimes, there are paths/files named with non-printable characters, for example (listed with <code>ls -b</code>):</p>
  
  <p><code>important_document\033[D\033[-</code></p>
  
  <p>These paths/file names are put into a string held by an object which in turn is marshalled into an XML document like so (<code>writer</code> is ):</p>
  
  <pre><code>JAXBContext context = JAXBContext.newInstance(Inventory.class);
  Marshaller marshaller = context.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
  marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
  marshaller.marshal(inventory, writer);
  </code></pre>
  
  <p>The marshaller doesn't complain about the unprintable characters and happily creates the XML document, which is rejected by other tools as invalid XML.</p>
  
  <p><strong>Question</strong>: Is there any way to make the marshaller encode non-printable characters in the output?</p>
  
  <p>I could clean the path/file name but I'd rather it happened document-wide without me having to clean all the individual data points.</p>