title: how to remove whitespace and carriage return in xml using xstream
body: <p>I am trying to linearize (remove whitespaces and carriage return) to compact XML. </p>
  
  <p>Input is </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;books&gt; 
      &lt;book&gt; 
         &lt;title&gt;Basic XML&lt;/title&gt; 
         &lt;price&gt;100&lt;/price&gt; 
         &lt;qty&gt;5&lt;/qty&gt; 
      &lt;/book&gt; 
      &lt;book&gt; 
          &lt;title&gt;Basic Java&lt;/title&gt; 
          &lt;price&gt;200&lt;/price&gt; 
          &lt;qty&gt;15&lt;/qty&gt; 
      &lt;/book&gt; 
  &lt;/books&gt;
  </code></pre>
  
  <p>Output is as follows. </p>
  
  <p>77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4gDQo8Ym9va3M+IA0KICAg
  PGJvb2s+IA0KICAgICAgIDx0aXRsZT5CYXNpYyBYTUw8L3RpdGxlPiANCiAgICAgICA8cHJpY2U+
  MTAwPC9wcmljZT4gDQogICAgICAgPHF0eT41PC9xdHk+IA0KICAgPC9ib29rPiANCiAgIDxib29r
  PiANCiAgICAgPHRpdGxlPkJhc2ljIEphdmE8L3RpdGxlPiANCiAgICAgPHByaWNlPjIwMDwvcHJp
  Y2U+IA0KICAgICA8cXR5PjE1PC9xdHk+IA0KICAgPC9ib29rPiANCjwvYm9va3M+</p>
  
  <p>Code to convert is as follows.</p>
  
  <p>public class XMLCompactTest {</p>
  
  <pre><code>public void testCompact() throws SAXException, IOException,
          ParserConfigurationException {
  
      final InputStream is =
              XMLCompactTest.class.getResourceAsStream("/example.xml");
  
      final byte[] bytes = IOUtils.toByteArray(is);
      final byte[] compactedBytes = compactXml(bytes);
  
      final String after = new String(compactedBytes);
  
      System.out.println(after);
  }
  
   public static byte[] compactXml(final byte[] value)
          throws SAXException, IOException, ParserConfigurationException {
  
      final ByteArrayOutputStream bout = new ByteArrayOutputStream();
      final XStream xs = new XStream();
      xs.autodetectAnnotations(true);
      xs.setMode(XStream.ID_REFERENCES);
      //xs.marshal(value, new CompactWriter(new OutputStreamWriter(bout, "UTF-8")));
      xs.marshal(value, new CompactWriter(new OutputStreamWriter(bout)));
  
      return bout.toByteArray();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Any help is very much appreciated, I have referred to other answers that deal with compacting xml and they do not seem to work for me. I am using xstream 1.4.3. </p>
  
  <p>I am expecting a single line compacted and decoded xml. </p>
  
  <p>Kind Regards. </p>