爲什麼我在輸出中獲得兩次我的字符串?XML :: Twig爲什麼輸出提取的字符串兩次?
#!/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>
奇怪的是,這是我原來在我的答案:)然而,文檔確實說,也提供了使用與「元素」沖洗的例子(http://search.cpan.org/dist/XML-Twig/Twig。下午#Processing_an_XML_document_chunk_by_chunk)。 – draegtun 2010-01-07 11:10:54
是的,沖洗一個元素衝到該元素,我會修復文檔。謝謝 – mirod 2010-01-10 10:13:22