我只需要在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>
如何刪除外部參照標記並保留其內容?
謝謝一切順利.. – user1811486