http://qs1969.pair.com?node_id=11136468

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

I have several xml files from where I want to read data and put it together in a single xml file. The origin files look all like this like this:
<testsuites> <testsuite name="test_suite_name" ...> <testcase name="test1" .../> <testcase name="test2" .../> <testsuite name="some_name" ...> </testsuites>
So, basically a single node "testsuite" which contains several "testcases" in each file. So I basically want to extract the "testsuite" node from each file and put it into a new file. I also would like to modify the attribute "name" of each testsuite. So far I have:
my $dom = XML::LibXML::Document->new('1.0', 'utf-8'); my $xml1 = XML::LibXML->load_xml(location => 'file1.xml'); my $xml2 = XML::LibXML->load_xml(location => 'file2.xml'); my $root = $dom->createElement('testsuites'); $dom->setDocumentElement($root); my $testsuite1 = $xml1->findnodes('//testsuite'); my $testsuite2 = $xml2->findnodes('//testsuite'); my $child = $dom->createElement($testsuite1); # <-- fails $root->appendChild($child); open XML, ">result.xml"; print XML $dom->toString(); close XML;
$testsuite1 is a XML::LibXML::NodeList object type. Is there a way to use that object to inject it in some way to $doc?