You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by mm...@lycos-inc.com on 2001/04/04 15:29:33 UTC
xalanj/InputSource/encoding question
We're running into an odd little problem with xalan-j around
encodings and interpretation... We have XML getting generated
from a number of sources, usually in latin1, but our problem
case happens when the output is utf-8.
The problem occurs when a utf-8 document containing high-bit
or multibyte characters gets loaded into a java String and then
run through xalan.
What i think is happening is that the process of loading the
xml into a java String is implicitly treating the bytes as latin1
so the java String (which is internally ucs2) in effect just pads
every byte with a null high byte. When you run the String
through xalan, of course those utf-8 bytes aren't viewed properly.
The part that puzzles me is that you can have an xml document
that says
<? xml version="1.0" encoding="iso-8859-1"?>
<TAG>blah blah blah</TAG>
loaded into a java String (by definition ucs2) and run through
xalan properly. Now, by the time xalan gets it out of the String,
all those bytes are *really* 2 bytes and it's *really* ucs2, not
iso-8859-1.
Since ucs2 is a superset of iso-8859-1, does xalanj make an
exception when processing a ucs2 java String saying it's latin1?
Is xalanj going to try an make exceptions for other encodings?
I guess my question would come down to how xalanj handles
the xml declaration line in a java String. A utf-8 xml document
doesn't need and in our case doesn't have an explicit <?xml?>
line. So if you then take it and force a null high byte in between
every byte in the document, you've got a ucs2 string also
without an explicit declaration.
In this case, is xalanj figuring a java String without an explicit
declaration is functionally the same from the xml point of view
as an utf-8 stream of bytes without an explicit declaration?
Would adding an explicit encoding="utf-8" get xalanj to apply
more flexible interpretation to a java String?
thanks
-mark