我只需要在 xml 文件中删除一些标签。
xml:
<p>Originally published <xref ref-type="bibr" rid="ref155">Klein, F. (1978)</xref> <i>Priam Books. Reproduced by permission of the author.</p>
脚本:
use XML::Twig;
my $xml_twig_content = XML::Twig->new(
keep_encoding => 1,
twig_handlers => {
keep_atts_order => 1,
'xref' => \&xref,
},
pretty_print => 'indented',
);
$xml_twig_content->parsefile('sample.xml');
sub xref {
my ($xml_twig_content, $xref) = @_;
my $XrefName = $xref->att('ref-type');
if ($XrefName =~ /^bibr$/si){
$xref->delete;
}
}
我得到了输出:
<p>Originally published <i>Priam Books. Reproduced by permission of the author.</p>
我需要输出:
<p>Originally published Klein, F. (1978) <i>Priam Books. Reproduced by permission of the author.</p>
如何删除外部参照标签并保留其内容?