Pourquoi ai-je ma chaîne deux fois dans la sortie?Pourquoi XML :: Twig génère-t-il deux fois la chaîne extraite?
#!/usr/bin/perl
use warnings;
use strict;
use XML::Twig;
my $string = '<cd_catalogue><title>Hello, World!</title></cd_catalogue>';
my $t= XML::Twig->new( twig_handlers => { cd_catalogue => \&cd_catalogue, },
pretty_print => 'indented',
);
$t->parse($string);
sub cd_catalogue {
my($t, $cd_catalogue) = @_;
$cd_catalogue->flush;
}
# Output:
#<cd_catalogue>
# <title>Hello, World!</title>
#</cd_catalogue>
#<cd_catalogue>
# <title>Hello, World!</title>
#</cd_catalogue>
Etrangement c'est ce que j'ai mis à l'origine dans ma réponse :) Cependant la documentation dit et fournit aussi des exemples d'utilisation de flush avec des "éléments" (http://search.cpan.org/dist/XML-Twig/Twig. pm # Processing_an_XML_document_chunk_by_chunk). – draegtun
oui, rinçage sur un élément flush jusqu'à cet élément, je vais réparer les docs. Merci – mirod