trans.transform(xmlSource, htmlResult) fails

R

rob

Hi all, I have some xml that has the cent character in it
( not sure it it will post but here it is -> ¢ )

I get this error

(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8
sequence.

when executing

java org.apache.xalan.xslt.Process -IN cent.xml -XSL cent.xsl -OUT
cent.html

anyhow, I am trying to use

my cent.xml is
********************************************
<?xml version="1.0" encoding="UTF-8"?>
<EMAIL>
<L>10¢</L>
</EMAIL>
*********************************************
my cent.xsl is
============================
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="/EMAIL/L"/>

</body>
</html>
</xsl:template>
</xsl:stylesheet>
=============================

I think is has to do with the encoding because if I change my
encoding="UTF-8" to encoding="ascii" in my xml
I generates the html (but it did not convert the cent char properly,
but at least no error)

thanks for any help
 
M

Martin Honnen

rob said:
Hi all, I have some xml that has the cent character in it
( not sure it it will post but here it is -> ¢ )

I get this error

(Location of error unknown)XSLT Error
(javax.xml.transform.TransformerException):
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8
sequence.

Sounds like the XML claims it is UTF-8 encoded but it is not, rather
that cent symbol is encoded as one byte.
So make sure that the XML correctly declares its encoding e.g.
<?xml version="1.0" encoding="ISO-8859-1"?>
 
R

rob

Martin, thank you so much, I am a bit weak on the xml conversion
stuff, so I didn't know where to turn, thanks for taking the time
to reply, I really appreciate it, it works great.


will changing
<?xml version="1.0" encoding="UTF-8"?>
to
<?xml version="1.0" encoding="ISO-8859-1"?>

break any transformations that you know of?
Typically the fiels I am transforming do not have the
extended chars like the cent char,
 
M

Martin Honnen

rob wrote:

will changing
<?xml version="1.0" encoding="UTF-8"?>
to
<?xml version="1.0" encoding="ISO-8859-1"?>

break any transformations that you know of?
Typically the fiels I am transforming do not have the
extended chars like the cent char,

The suggestion is more an example on what you could change. I don't know
whether ISO-8859-1 is the encoding the author of the XML has used. So
what you really need to do is declare the encoding you or someone else
uses when creating the XML.
 
R

rob

I have a byte array I get from the DB then convert it to a string,
and I create the XML via JDOM from this string,
then transform the JDOM dom , so I can call the format method
with any encoding I choose,

but the underlying byte array has the cent char
and when I left my generated xml encoded via UTF-8, it threw the error,
but this works if I convert the

here is where i dump the xml to the file system after I have already
create a JDom document object from the DB

Format format = Format.getPrettyFormat();
format.setEncoding("ISO-8859-1");
XMLOutputter outputter = new XMLOutputter(format);
outputter.output(document, new FileWriter( new File("cent.xml") );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top