dbmathis has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

Forgive me if I use improper terminology or just make a fool of myself with these code examples.

I have two xml documents, one is called input.xml and the other cde.xml. input.xml simply contains a tree that I wan't to add / merge into cde.xml

Here is the code that I have so far which does not work. I am not even sure that what I am trying to do is possible at this point. I may have to just write code to add these elements to cde.xml without copy or paste.

#!/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; }

XML Example:

input.xml
<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>

Snippet of cde.xml
..... <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"> ....

I just want the children of input.xml/Questions added to the children of cde.xml/Questions. The problem is that Comments has children and when I paste it tells me I can't paste a tree.

Hope this makes sense.