title: XML Invalid byte 1 of 1-byte UTF-8 sequence
body: <p>I have a program that takes two xml files and merge into one, while I'm doing this, I managed to convert from "and " to "and &#8217;". Not talking about why I'm doing this, here's the code snippet, removing "<code>&amp;#8217;</code>" error no longer exist that's why I paste it here.</p>
  
  <pre><code>convertedString = replace(convertedString, (String)"and ", 
                  (String)"and &amp;#8217;");
  convertedString = replace(convertedString, (String)"&amp;quot;", 
                  (String)"\\\"");
  convertedString = StringEscapeUtils.unescapeHtml(convertedString);
  </code></pre>
  
  <p>with printDocument method:</p>
  
  <pre><code>private static void printDocument(Document doc, OutputStream out) 
      throws IOException, TransformerException 
      {     
          TransformerFactory tf = TransformerFactory.newInstance();     
          Transformer transformer = tf.newTransformer();     
          transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");     
          transformer.setOutputProperty(OutputKeys.METHOD, "xml");     
          transformer.setOutputProperty(OutputKeys.INDENT, "yes");     
          transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");     
          transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-" +
                  "amount", "4");      
          transformer.transform(new DOMSource(doc),           
                  new StreamResult(new OutputStreamWriter(out, "UTF-8"))); 
      }
  </code></pre>
  
  <p>running my program I get</p>
  
  <pre><code>com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
      at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
      at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
      at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
      at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(XMLEntityScanner.java:1416)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2793)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
  </code></pre>
  
  <p>Even though it might to do with UTF-8 in printDocument() method, changing it to ISO-8859-1 wasn't going to help.</p>
  
  <p>So could anyone help me what the issue is? Much appreciated</p>