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, i.e.:
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 some of the data in the database is binary - i.e. there are non UTF-8 characters in there. When this occurs, XML::Generator::DBI detects this and outputs the data as follows in the XML file:
<foo dbi:encoding='base64'>VGhpcyByZXBvcnQgbGlzdHMgYWxsIGZpbGVzIGhhdmluZyBhY2Nlc3NlcyB0byBkYXRhYmFzZSB0
YWJsZXMuDQpJdCBwcm92aWRlcyB0aGUgZm9sbG93aW5nIGluZm9ybWF0aW9uOiAgRmlsZSBmdWxs
IG5hbWUsIGFjY2Vzc2VkIHRhYmxl
</foo>
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: 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.