0

我现在阅读了一个 xml 文件,我做了特定的标签注释,但它省略了然后插入注释......

XML:

<book>
  <book-meta>
    <book-id pub-id-type="doi">1545</book-id>
</book-meta>
</book>

脚本:

 use strict;
use XML::Twig;
open(my $out, '>', 'Output.xml') or die "can't Create stroy file $!\n";

my $story_file = XML::Twig->new(
                               twig_handlers =>{
                                        'book-id' => sub {$_->set_comment('drop')},
                                        keep_atts_order => 1,
                                        },
                                        pretty_print => 'indented',
                              );

$story_file->parsefile('sample.xml');
$story_file->print($out);

我的输出是:

<book>
  <book-meta><!--drop-->
  </book-meta>
</book>

我需要:

<book>
  <book-meta>
    <!--<book-id pub-id-type="doi">1545</book-id>-->
</book-meta>
</book>

我在这个过程中做错了什么......

4

1 回答 1

1

只需将注释文本设置为树枝的 XML:

'book-id' => sub { $_->set_comment($_->sprint) },
于 2012-11-01T09:04:26.010 回答