XSLT mapping issue with UTF-8 encoding

Hi all,
I am working with an XSLT mapping and am facing an error as:
SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence

I am passing an xml with tag as <?xml version="1.0" encoding="UTF-8"?>
Is their any way that we can actually confirm if the xml complies to UTF-8 encoding?

Can anybody please tell me as to how to avoid this error?

Thanks in advance.

Krithiga M

hi, when you convert document to XML string (or where ever you make the XML string) make sure that you set encoding to UTF-8 explicitly, otherwise the encoding will be of the JVM default. If you receive the XML from external system then try convert to document and then to XML string with encoding as UTF-8.
I think the issue is due to the xml is ISO or Windows encoding and XSLT parser considers as UTF-8.

  • hope this helps

Hi DC,
Thanks for your reply.
Actually am getting a response from a webservice. It is a document already.
As you suggested, i have again done the encoding explicitly as follows just in case it helps

doc to string
string to node → specified encoding as UTF-8
node to doc
doc to string

Not sure if we can do a round about like this, but at least thought if this could solve the problem.

but even then am getting the same error:(

Krithiga Muralidharan

you need to know the original encoding of the content that you received from you WS call. (you may find with the WS provider)
once you get it, after convert it to a string, use the java.nio.charset.CharsetDecoder and CharsetEncoder to do the conversion (google on sample of usage)