I new to xml twig, how can I add space between two elements in xml-twig?
Input:
<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>
Script:
$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;
}
output:
<xml>
<fig id="fig6_4">
[Figure 4] <caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>
i need:
<xml>
<fig id="fig6_4">
<xref ref-type="page" id="page_54"/>[Figure 4] <caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>
how can i inset space between two elements…..
I would use a handler on
fig/label, since that’s the only element that needs to be modified. The code in the handler then needs to suffix the element with whitespace, then erase the tag: