trans.transform(xmlSource, htmlResult) fails

Discussion in 'XML' started by rob, May 5, 2006.

  1. rob

    rob Guest

    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
     
    rob, May 5, 2006
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, May 5, 2006
    #2
    1. Advertising

  3. rob

    rob Guest

    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,
     
    rob, May 5, 2006
    #3
  4. 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/
     
    Martin Honnen, May 5, 2006
    #4
  5. rob

    rob Guest

    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") );
     
    rob, May 5, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    1
    Views:
    712
    John Saunders
    Nov 18, 2003
  2. Jonathan N. Little
    Replies:
    13
    Views:
    5,730
    Jonathan N. Little
    Feb 6, 2005
  3. Anthony Bollinger

    Trans from ASP to ASP.NET 2.0 via 1.0

    Anthony Bollinger, May 12, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    406
    Anthony Bollinger
    May 14, 2006
  4. clyyy2002
    Replies:
    1
    Views:
    117
    Chad Z. Hower aka Kudzu
    May 14, 2005
  5. Pen Ttt

    trans string into array

    Pen Ttt, Dec 31, 2010, in forum: Ruby
    Replies:
    4
    Views:
    127
    Brian Candler
    Jan 1, 2011
Loading...

Share This Page