What is your environment? On my machine it works just fine (see below). I use this to get the relevant information:
alias ts='perl -v | grep "This is"; \ perl -e"use XML::Twig; \ print qq{XML::Twig: \$XML::Twig::VERSION\n}"; \ perl -e"use XML::Parser; \ print qq{XML::Parser: \$XML::Parser::VERSION\n}"; \ xmlwf -v;'
Note that if the last line (xmlwf... returns an error you are probably using expat 1.95.2 (xmlwf did not support the -v option at the time).
This is my test environment:</p
This is perl, v5.6.1 built for i686-linux XML::Twig: 3.09 XML::Parser: 2.31 xmlwf using expat_1.95.5
In any case this works fine for me:
#!/usr/bin/perl -w use strict; use XML::Twig; sub Node { my ($twig, $node) = @_; my $txt = $node->text (); my $id = $node->att ('id'); #print two strings individually print "$id\n"; print "$txt\n"; #print list - OK print "1) list: ", $id, " ", $txt, "\n"; #print with string concat - still OK print "2) concat: $id $txt\n"; #the concatenated string DOES match the Latin1 part my $res = "$id $txt" =~ /$txt/ ? "match" : "NO match"; print "\"$id $txt\" =~ /$txt/ => $res\n"; } package main; my $twig = XML::Twig->new (KeepEncoding => 1, TwigHandlers => {Node => + \&Node}); $twig->parse (\*DATA); __DATA__ <?xml version="1.0" encoding="ISO-8859-1"?> <Document> <Node id="50">fünfzig</Node> </Document>
A last remark: there is nothing in the XML spec that specifies what the XML processor (they don't even use the word parser) is supposed to report. It just happens that most parsers convert to UTF-8 (or probably UTF-18 in the Java world) because it makes sense. At least expat and libxml do, see The internal encoding, how and why for a good explanation. The keep_encoding option of XML::Twig is quite atypical, and it is there for the common case of all documents being in the same, known in advance (1-byte) encoding.
In reply to Re: Problems with string concatenation and encodings
by mirod
in thread Problems with string concatenation and encodings
by pike
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |