I have a Postgres database encoded in UTF-8. I am using Perl with the following modules:

use DBI use XML::Generator::DBI use XML::SAX::Writer

to extract data in the Postgres database to an XML file using a query customised from this very website! :

use DBI; use XML::Generator::DBI; use XML::SAX::Writer; my $dbh = DBI->connect("dbi:Pg:dbname=postgres;host=MYHOST;port=2278", username, password, {RaiseError => 1}, ); my $handler = XML::SAX::Writer->new( Output => 'foo.xml' ); my $generator = XML::Generator::DBI->new( Handler => $handler, dbh => $dbh, Indent => 1, ); $select = qq( !!!!SQL QUERY!!!!! ); $generator->execute( $select, undef, RootElement => 'root', );

This works well and I get a valid XML document as a result. My problem is that XML::Generator::DBI is outputting some of the data follows in the XML file:

<foo dbi:encoding='base64'>VGhpcyByZXBvcnQgbGlzdHMgYWxsIGZpbGVzIGhhdml +uZyBhY2Nlc3NlcyB0byBkYXRhYmFzZSB0 YWJsZXMuDQpJdCBwcm92aWRlcyB0aGUgZm9sbG93aW5nIGluZm9ybWF0aW9uOiAgRmlsZS +BmdWxs IG5hbWUsIGFjY2Vzc2VkIHRhYmxl </foo>

The original script that created the data in the database has the following for the above base64:

This report lists all files having accesses to database tables.!xD!`!xA!`It provides the following information: File full name, accessed table

in other words, the carriage return is causing the module to convert the text to base64.

The namespace is also bound to the URL http://axkit.org/NS/xml-generator-dbi. This is correct behaviour according to the module documentation, but what I want to know is two fold:

a) why is this conversion taking place on carriage returns as I was under the impression they were allowed characters in UTF-8?

b) is it possible to somehow transform this base64 encoded string into UTF-8 so that i can actually use it?

I'm no Perl expert at all, nor Postgres for that matter, so go easy! many thanks.


In reply to Extracting data from Postgres database to XML via Perl - encoding issue by Anonymous Monk

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.