Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting data from Postgres database to XML via Perl - encoding issue
by moritz (Cardinal) on Dec 13, 2010 at 12:50 UTC | |
|
Re: Extracting data from Postgres database to XML via Perl - encoding issue
by locked_user sundialsvc4 (Abbot) on Dec 14, 2010 at 15:02 UTC |