title: I have UTF-8 - but still get "Invalid byte 1 of 1-byte UTF-8 sequence"
body: <p>I create a XML String on the fly (NOT reading from a file). Then I use Cocoon 3 to transform it via FOP to a PDF. Somewhere in the middle Xerces runs. When I use the hardcoded stuff everything works. As soon as I put a german Umlaut into the database and enrich my xml with that data I get:</p>
  
  <pre><code>Caused by: org.apache.cocoon.pipeline.ProcessingException: Can't parse the XML string.
  at org.apache.cocoon.sax.component.XMLGenerator$StringGenerator.execute(XMLGenerator.java:326)
  at org.apache.cocoon.sax.component.XMLGenerator.execute(XMLGenerator.java:104)
  at org.apache.cocoon.pipeline.AbstractPipeline.invokeStarter(AbstractPipeline.java:146)
  at org.apache.cocoon.pipeline.AbstractPipeline.execute(AbstractPipeline.java:76)
  at de.grobmeier.tab.webapp.modules.documents.InvoicePipeline.generateInvoice(InvoicePipeline.java:74)
  ... 87 more
  
  Caused by: 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)
  </code></pre>
  
  <p>I have then debugged my app and found out, my "Ä" (which comes frome the database) has the byte value of 196, which is C4 in hex. This is what I have expected according to this: <a href="http://www.utf8-zeichentabelle.de/" rel="noreferrer">http://www.utf8-zeichentabelle.de/</a></p>
  
  <p>I do not know why my code fails.</p>
  
  <p>I have then tried to add a BOM manually, like that:</p>
  
  <pre><code>byte[] bom = new byte[3];
  bom[0] = (byte) 0xEF;
  bom[1] = (byte) 0xBB;
  bom[2] = (byte) 0xBF;
  String myString = new String(bom) + inputString;
  </code></pre>
  
  <p>I know this is not exactly good, but I tried it - of course it failed. I have tried to add a xml header in front:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p>Which failed too. Then I combined it. Failed.</p>
  
  <p>After all I tried something like that:</p>
  
  <pre><code>xmlInput = new String(xmlInput.getBytes("UTF8"), "UTF8");
  </code></pre>
  
  <p>Which is doing nothing in fact, because it is already UTF-8. Still it fails.</p>
  
  <p>So... any ideas what I am doing wrong and what Xerces is expecting from me?</p>
  
  <p>Thanks
  Christian</p>