title: How to prevent XMLStreamWriter writeCharacter method converts \r to &#xd;
body: <p>How do I prevent from XMLStreamWriter writeCharacter method converts \r to &#xd; upon writing to the file.</p>
  
  <p>I have to write the XML formatted already. However, if I use Indentingxmlstreamwriter, it only uses \n instead of \r\n. </p>
  
  <p>Here is the sample code:</p>
  
  <hr>
  
  <pre><code>File outputFile = new File(filePath.concat(filename));
  FileOutputStream outputFileStream = null;
  try {
      outputFileStream = new FileOutputStream(outputFile);
  }
  catch (FileNotFoundException e1) {
      e1.printStackTrace();
  }
  
  XMLOutputFactory factory = XMLOutputFactory.newInstance();
  BufferedOutputStream outputStream = new BufferedOutputStream(outputFileStream);
  
  try {
      writer = factory.createXMLStreamWriter(outputStream);
      //indwr = new IndentingXMLStreamWriter(writer);
  }
  catch (XMLStreamException e) {
  }
  
  
  try {
  
      //writer.setIndentStep("  ");
      writer.writeStartDocument("UTF-8","1.0");
  
      writer.writeCharacters("\r\n");
      writer.writeStartElement("document");
  
      writer.writeCharacters("\r\n");
      writer.writeCharacters("  ");
  
      writer.writeStartElement("data");
      writer.writeAttribute("name", "value");
  
      writer.writeCharacters("\r\n");
      writer.writeCharacters("    ");
  
      writer.writeStartElement("data2");
      writer.writeAttribute("name", "value");
  
      writer.writeEndElement();
  
      writer.writeCharacters("\r\n");
      writer.writeCharacters("  ");
      writer.writeEndElement();
  
      writer.writeCharacters("\r\n");
      writer.writeEndElement();
  
      writer.writeEndDocument();
  
      writer.flush();
      writer.close();
  
  }
  catch (XMLStreamException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <hr>
  
  <p>Any suggestions? Thanks!</p>