我是 xml 树枝的新手,如何在 xml-twig 中的两个元素之间添加空格?
输入:
<xml>
<fig id="fig6_4">
<label><xref ref-type="page" id="page_54"/>[Figure 4]</label>
<caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>
脚本:
$xml_twig_content = XML::Twig->new(
twig_handlers => {
'fig' => \&figure,
},
);
$xml_twig_content->parsefile('sample.xml');
sub figure{
my ($xml_twig_content, $figure) = @_;
my @figchild = $figure->children;
foreach my $chid (@figchild){
if ($chid->name =~ /label/){
my $t = $chid->text;
$chid->set_inner_xml($t . ' ');
$chid->erase;
}
输出:
<xml>
<fig id="fig6_4">
[Figure 4] <caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>
我需要:
<xml>
<fig id="fig6_4">
<xref ref-type="page" id="page_54"/>[Figure 4] <caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>
我怎样才能在两个元素之间插入空格.....