dbmathis has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w # use strict; use warnings; use XML::Twig; my $input = XML::Twig->new( twig_roots => { Questions => \&comments }, ); $input->parsefile( 'input.xml'); my $cde = XML::Twig->new( twig_roots => { QQ_Manifest => \&questions } +, twig_print_outside_roots => 1, keep_spaces => 1, ); $cde->parsefile( 'cde.xml'); $cde->flush; sub questions { my( $cde, $questions) = @_; my $question = $questions->first_child( 'Questions'); foreach ( @comments ) { $_->paste( last_child => $question); } } sub comments { my( $input, $comments) = @_; my $comment = $comments->first_child( 'Comments'); push @comments, $comment; }
<Questions> <Comments number="12"><Prompt><![CDATA[Question placeho +lder for missing question in RC]]></Promp t><Response score="1.0"><![CDATA[No answer available]]></Response></Co +mments> <Comments number="13"><Prompt><![CDATA[Question placeho +lder for missing question in RC]]></Promp t><Response score="1.0"><![CDATA[No answer available]]></Response></Co +mments> <Comments number="14"><Prompt><![CDATA[Question placeho +lder for missing question in RC]]></Promp t><Response score="1.0"><![CDATA[No answer available]]></Response></Co +mments> </Questions>
..... <QQ_Manifest> <Applicant id="applicant1" person_id="50-8082308" email="jac +k_black@aolsuxor.com"/> <Scoresheet id="scoresheet1" person_id="5080438" req_id="564 +3sa34" score="0.8000dsa001" timespent="0" /> <Questions includes_responses="yes"> <No number="10"> ....
|
|---|