Hi,

NB: I've been living inside my ASCII shell for as long as possible, but I'm just starting to look at unicode data. My understanding of how to manipulate it is limited.

I've been using a perl script to turn a bunch of Microsoft Excel files into XML files, and from there, import them into a MySQL DB. Recently I've spotted some non-ASCII values in the Excel files, such as "ß". I decided that, since Perl's got Unicode support, I'll turn the contents of the spreadsheets into utf8, then import them into the database, and display the results in an HTML page via another Perl script.

I'm having trouble with this, and I'm not sure where the problem is. What I do:

  1. Run Encode's from_to on each data field to go from from "iso-8859-1" to "utf8"
  2. Put the data in a hash, and print with something very similar to the following:
my $xs = new XML::Simple(ForceArray => 1, KeyAttr => 1, KeepRoot => 1, + NoAttr => 1); print '<?xml version="1.0" encoding="UTF-8"?>', "\n"; print $xs->XMLout(\%foo, RootName => "foo");

Assumption Number 1: I'm assuming, at this point, my XML files will contain valid Unicode data (there's a couple of funny characters in place of the German "double-s" character). I do not know how to prove this, but the files are slurped in again with XML::Simple ok.

The data is then read in by another Perl script (using XML::Simple), and put into the database (MySQL 4.0.20, which may have dubious utf8 support -- I'm not sure). The column in question was declared of SQL type "varchar(255) character set utf8", and the field in the database looks the same (to me) as the value in the XML file.

Assumption Number 2: The utf8 data has made it into the database successfully.

I then want to display the same data (using HTML::Template) in an HTML file. The trouble is, even with a '<?xml version="1.0" encoding="UTF-8"?>' at the front, the HTML as displayed in my browser (and in the HTML source) isn't the correct character. It looks like it's the same "funny characters" as in the XML file and the database.

Assumption Number 3: I need to do something here to convert the value stored in the database to the HTML unicode entity.

Are my assumptions correct? If so, how do I get well-formed, valid, (and correct!) HTML in my browser?

Cheers


davis
It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.

In reply to Mildly OT: Excel Order Forms -> XML -> MySQL -> HTML with unicode by davis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.