<?xml version="1.0" encoding="windows-1252"?>
<node id="751778" title="XML::Twig and Processing Instructions" created="2009-03-19 12:28:00" updated="2009-03-19 12:28:00">
<type id="115">
perlquestion</type>
<author id="482313">
eff_i_g</author>
<data>
<field name="doctext">
Monks,
&lt;br&gt;&lt;br&gt;
Given the s&lt;c&gt;[&lt;/c&gt;ai&lt;c&gt;]&lt;/c&gt;mple XML file:

&lt;c&gt;
&lt;root&gt;
	&lt;element&gt;One&lt;?xpp qa?&gt;Two&lt;/element&gt;
&lt;/root&gt;
&lt;/c&gt;

I want to wrap "Two" in &lt;c&gt;&lt;?xpp bold?&gt;&lt;/c&gt; and &lt;c&gt;&lt;?xpp /bold?&gt;&lt;/c&gt;.
&lt;br&gt;&lt;br&gt;
My approach is to create a &lt;c&gt;twig_root&lt;/c&gt; of &lt;c&gt;element&lt;/c&gt;, loop through its children, find "Two", then add the PIs.
&lt;br&gt;&lt;br&gt;
The trouble is that I'm getting &lt;b&gt;one&lt;/b&gt; child ("One&lt;?xpp qa?&gt;Two"), when I think I should be getting &lt;b&gt;three&lt;/b&gt; ("One", "&lt;?xpp qa?&gt;", "Two"). Alas, the PI is being lumped in with the PCDATA.
&lt;br&gt;&lt;br&gt;
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?
&lt;br&gt;&lt;br&gt;
Insights are appreciated.
&lt;br&gt;&lt;br&gt;
P.S. The test code:
&lt;c&gt;
use strict;
use warnings;
use XML::Twig;

my $XML = XML::Twig-&gt;new(
	twig_roots =&gt; {
		'element' =&gt; sub {
			for my $child ($_-&gt;cut_children()) {
				$child-&gt;print();
				print "\n";
			}
		}
	},
	pretty_print =&gt; 'indented'
);
$XML-&gt;parse(*DATA);
print "\n";

__DATA__
&lt;root&gt;
	&lt;element&gt;One&lt;?xpp qa?&gt;Two&lt;/element&gt;
&lt;/root&gt;
&lt;/c&gt;</field>
</data>
</node>
