perlquestion
eff_i_g
Monks,
<br><br>
Given the s<c>[</c>ai<c>]</c>mple XML file:
<c>
<root>
<element>One<?xpp qa?>Two</element>
</root>
</c>
I want to wrap "Two" in <c><?xpp bold?></c> and <c><?xpp /bold?></c>.
<br><br>
My approach is to create a <c>twig_root</c> of <c>element</c>, loop through its children, find "Two", then add the PIs.
<br><br>
The trouble is that I'm getting <b>one</b> child ("One<?xpp qa?>Two"), when I think I should be getting <b>three</b> ("One", "<?xpp qa?>", "Two"). Alas, the PI is being lumped in with the PCDATA.
<br><br>
Sure, I could parse the PI out of the PCDATA, but that doesn't seem right. Perhaps I've a misunderstanding, a bug, or have overlooked something in the [mod://XML::Twig] docs?
<br><br>
Insights are appreciated.
<br><br>
P.S. The test code:
<c>
use strict;
use warnings;
use XML::Twig;
my $XML = XML::Twig->new(
twig_roots => {
'element' => sub {
for my $child ($_->cut_children()) {
$child->print();
print "\n";
}
}
},
pretty_print => 'indented'
);
$XML->parse(*DATA);
print "\n";
__DATA__
<root>
<element>One<?xpp qa?>Two</element>
</root>
</c>