slugger415 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I'm using XML::Twig to parse some XML and output a new file. It seems to eat up any comments I have however. I've got comments set to keep but it doesn't seem to be keeping them.
my $twig= XML::Twig->new( 
  comments => 'keep',
  twig_handlers => { 'cmd' => \&cmd_processing,
);

Is something amiss?

Replies are listed 'Best First'.
Re: XML::Twig deletes comments
by toolic (Bishop) on Sep 01, 2011 at 19:13 UTC
    This works as expected (it keeps the comments):
    use warnings; use strict; use XML::Twig; my $str = <<EOF; <foo> <!-- hello comment --> <bar>goo</bar> </foo> EOF my $t = XML::Twig->new(comments => 'keep'); $t->parse($str); $t->print(); print "\n"; __END__ <foo> <!-- hello comment --> <bar>goo</bar></foo>
    Try to create a small example like this that anyone can run which still demonstrates the problem.
      Thank you, got it working! much appreciated. Scott