[Vienna-pm] Seltsames XML::Parser-Problem

Peter J. Holzer hjp at wsr.ac.at
Fri Mar 4 11:56:35 PST 2005


Gegeben sei folgendes Script 

----------<test_xml_dom_2>--------------------------------------------
#!/usr/local/bin/perl -w
use strict;
use XML::DOM;
use Data::Dumper;
use 5.8.3;	# see [filehandle_utf8]

for my $file (@ARGV) {
    my $parser = new XML::DOM::Parser;
    my $doc = $parser->parsefile ($file);
    my $f = FileHandle->new("$file.out", ">:utf8") or die "cannot open $file.out: $!";
    $doc->print($f);
    $f->close() or die "cannot close $$: $!";
}
----------</test_xml_dom_2>-------------------------------------------

und folgendes Inputfile (in iso-8859-1 kodiert, d.h., das "ä" ist ein
Byte 0xE4):

----------<backup-fs2.xml>--------------------------------------------
<?xml version="1.0" encoding="iso-8859-1" ?>
<snippet>
   <body>
     <h3>Läuft
     wo?</h3>
   </body>
</snippet>
----------</backup-fs2.xml>-------------------------------------------

Dann erwarte ich als Output ein File namens backup-fs2.xml.out mit dem
gleichen Inhalt, nur in UTF-8 kodiert.

So ist es auch auf einem meiner Rechner. Auf anderen wird offenbar
doppelt in UTF-8 umgewandelt: Aus dem ä werden die vier Bytes 0xC3 0x83
0xC2 0xA4. Soweit ich sehe passiert das einmal beim Parsen und beim
Ausgeben noch einmal, weil der String beim Parsen nicht korrekt als
UTF-8 markiert wird. 

Entfernt man das Newline zwischen "Läuft" und "wo?", so bekommt man das
richtige Ergebnis.

Funktionieren tut es auf:

OS:		Fedora Core 2
Perl:		v5.8.3 built for i386-linux-thread-multi
expat:		1.95.7-1.1
XML::Parser:	2.34
XML::DOM:	1.43
glibc:		2.3.3-27.1

Nicht funktionieren tut es auf:

OS:		Redhat 9
Perl:		v5.8.6 built for i686-linux
expat:		1.95.5-2
XML::Parser:	2.34
XML::DOM:	1.43
glibc:		2.3.2-27.9.7

OS:		Debian Sarge
Perl:		v5.8.4 built for i386-linux-thread-multi
expat:		1.95.8-1
XML::Parser:	2.34
XML::DOM:	1.43
glibc:		2.3.2.ds1-20

XML::Parser und XML::DOM ist also in allen Fällen identisch. expat ist
einmal älter und einmal jünger als im funktionierenden Fall, wird es
also vermutlich auch nicht sein. Bleiben Perl (bei 5.8.3 gehts, bei
neueren nicht) oder die glibc (bei 2.3.2 gehts nicht, bei 2.3.3 schon).

Bevor ich mich in die unerquicklichen Tiefen von perl5 und der glibc2
stürze: Kann das noch wer nachvollziehen und eventuell weiter
eingrenzen?

	hp

-- 
   _  | Peter J. Holzer \Beta means "we're down to fixing misspelled comments in
|_|_) | Sysadmin WSR     \the source, and you might run into a memory leak if 
| |   | hjp at wsr.ac.at     \you enable embedded haskell as a loadable module and
__/   | http://www.hjp.at/ \write your plugins upside-down in lisp". --ae at op5.se
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 388 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/vienna-pm/attachments/20050304/8290286f/attachment.bin


More information about the Vienna-pm mailing list