Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:53:04+00:00 2026-05-27T10:53:04+00:00

I create a XML String on the fly (NOT reading from a file). Then

  • 0

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:

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)

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: http://www.utf8-zeichentabelle.de/

I do not know why my code fails.

I have then tried to add a BOM manually, like that:

byte[] bom = new byte[3];
bom[0] = (byte) 0xEF;
bom[1] = (byte) 0xBB;
bom[2] = (byte) 0xBF;
String myString = new String(bom) + inputString;

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:

<?xml version="1.0" encoding="UTF-8"?>

Which failed too. Then I combined it. Failed.

After all I tried something like that:

xmlInput = new String(xmlInput.getBytes("UTF8"), "UTF8");

Which is doing nothing in fact, because it is already UTF-8. Still it fails.

So… any ideas what I am doing wrong and what Xerces is expecting from me?

Thanks
Christian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:53:04+00:00Added an answer on May 27, 2026 at 10:53 am

    If your database contains only a single byte (with value 0xC4) then you aren’t using UTF-8 encoding.

    The character “LATIN CAPITAL LETTER A WITH DIAERESIS” has a code-point value U+00C4, but UTF-8 can’t encode that in a single byte. If you check the third column “UTF-8 (hex.)” on UTF8-zeichentabelle.de you’ll see that UTF-8 encodes that as 0xC3 84 (two bytes).

    Please read Joel’s article “The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)” for more info.


    EDIT: Christian found the answer himself; turned out it was a problem in the Cocoon 3 SAX component (I guess it’s the alpha 3 version). It turns out that if you pass an XML as a String into the XMLGenerator class, something will go wrong during SAX parsing causing this mess.

    I looked up the code to find the actual problem in Cocoon-stax:

    if (XMLGenerator.this.logger.isDebugEnabled()) {
        XMLGenerator.this.logger.debug("Using a string to produce SAX events.");
    }
    XMLUtils.toSax(new ByteArrayInputStream(this.xmlString.getBytes()), XMLGenerator.this.getSAXConsumer();
    

    As you can see, the call getBytes() will create a Byte array with the JRE’s default encoding which will then fail to parse. This is because the XML declares itself to be UTF-8 whereas the data is now in bytes again, and likely using your Windows codepage.

    As a workaround, one can use the following:

    new org.apache.cocoon.sax.component.XMLGenerator(xmlInput.getBytes("UTF-8"),
           "UTF-8");
    

    This will trigger the right internal actions (as Christian found out by experimenting with the API).

    I’ve opened an issue in Apache’s bug tracker.

    EDIT 2: The issue is fixed and will be included in an upcoming release.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get an XML from website into a string strXML. Then I create an
I get an XML string from a certain source. I create a DOMDocument object
I want to create XML file from my Excel file through .NET (c#). My
Is it possible to use PHP's SimpleXML functions to create an XML object from
i want create XML file here is my following code String fileName = jasstech.xml;
I am trying to create an XML file using string data. (Which is itself
I need to create a keyed hash for a string of XML to send
I need to create XML in Perl. From what I read, XML::LibXML is great
In C#, I need to create XML files for use with Ivy and NAnt,
I'm trying to create an XML string and pass it to another method where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.