Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   trans.transform(xmlSource, htmlResult) fails (http://www.velocityreviews.com/forums/t237557-trans-transform-xmlsource-htmlresult-fails.html)

rob 05-05-2006 01:06 PM

trans.transform(xmlSource, htmlResult) fails
 
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:output 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


Martin Honnen 05-05-2006 01:21 PM

Re: trans.transform(xmlSource, htmlResult) fails
 


rob wrote:

> 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"?>




--

Martin Honnen
http://JavaScript.FAQTs.com/

rob 05-05-2006 01:55 PM

Re: trans.transform(xmlSource, htmlResult) fails
 
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,


Martin Honnen 05-05-2006 02:04 PM

Re: trans.transform(xmlSource, htmlResult) fails
 


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.



--

Martin Honnen
http://JavaScript.FAQTs.com/

rob 05-05-2006 02:14 PM

Re: trans.transform(xmlSource, htmlResult) fails
 
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") );



All times are GMT. The time now is 01:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.