Here's the situation: I've got a big ol' CSV file full of data exported from an MS SQL database. I need to massage this data into XML documents that can be parsed with XML::Parser. So far I've been using Text::xSV and XML::Writer to get the job done. All was well until I started getting errors from XML::Parser like this:

not well-formed (invalid token) at line 514, column 188, byte 72499 at /usr/local/lib/perl5/site_perl/5.6.1/i686-linux/XML/Parser.pm line +185

I get a few dozen of these. All the bytes they're pointing to are high-ASCII characters of some sort. I'm guessing this means I need to do something special to output clean UTF-8. Somehow I thought XML::Writer would take care of that, but I guess not.

My first attempt was to use Unicode::Map8 to translate the input data from Latin1 (a guess at the character set) to UTF-8. That didn't work. So I tried the umap utility, which I've used successfully in similar circumstances before:

umap latin1:utf8 < data.old > data.new

But XML::Parser doesn't like data.new any better than data.old.

So I come to the monks, on bended knee. I'd be happy to get anything from a new debugging technique or an RTFM link to an outright solution. Thanks!


In reply to Generating UTF-8 from nasty high ASCII input by samtregar

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.