On Fri, 22 Feb 2008 02:05:27 -0500, Glenn Maynard wrote:

> After this module corrupted my output data I just spent an hour trying to
> track down what I was doing wrong, since this module supposedly supported
> UTF-8.  Then, I find that this is a known bug for two and a half years.

Thanks for bringing this up again, and I agree, letting this bug rot
is a shame ...

I've created a tentative patch now which seems to fix the encoding
both for the printToFile() and the toString() funtcions.

I'm attaching the patch and my testcase, and I'd like to ask for
comments.

Cheers,
gregor
-- 
 .''`.   http://info.comodo.priv.at/ | gpg key ID: 0x00F3CFE4
 : :' :  debian: the universal operating system - http://www.debian.org/
 `. `'   member of https://www.vibe.at/ | how to reply: http://got.to/quote/
   `-    NP: Guns N' Roses: Welcome To The Jungle
--- libxml-dom-perl.orig/lib/XML/DOM.pm
+++ libxml-dom-perl/lib/XML/DOM.pm
@@ -35,6 +35,7 @@
 	   );
 use Carp;
 use XML::RegExp;
+use Encode;
 
 BEGIN
 {
@@ -485,8 +486,8 @@
 
 sub toString
 {
-    my $self = shift;
-    $$self;
+    my ($self, $encoding) = @_;
+    Encode::encode($encoding, $$self);
 }
 
 sub reset
@@ -1193,10 +1194,11 @@
 sub toString
 {
     my $self = shift;
+    my $encoding = $self->getXMLDecl()->getEncoding();
     my $pr = $XML::DOM::PrintToString::Singleton;
     $pr->reset;
     $self->print ($pr);
-    $pr->toString;
+    $pr->toString($encoding);
 }
 
 sub to_sax
@@ -1218,7 +1220,8 @@
 sub printToFile
 {
     my ($self, $fileName) = @_;
-    my $fh = new FileHandle ($fileName, "w") || 
+    my $encoding = $self->getXMLDecl()->getEncoding();
+    my $fh = new FileHandle ($fileName, ">:encoding($encoding)") || 
 	croak "printToFile - can't open output file $fileName";
     
     $self->print ($fh);

Attachment: xmldomencoding.tar.gz
Description: Binary data

Attachment: signature.asc
Description: Digital signature

Reply via email to