Note the input data you've shown isn't valid XML, and you haven't shown the expected output, so I have to guess at what you want. See How do I post a question effectively? and Short, Self-Contained, Correct Example.
As documented, ->findnodes in scalar context returns an XML::LibXML::NodeList object, which you can't pass to ->createElement. Here's one approach:
use warnings;
use strict;
use XML::LibXML;
my @files = ("file1.xml", "file2.xml", "file3.xml");
my $outfile = "result.xml";
my $newdom = XML::LibXML::Document->new('1.0', 'UTF-8');
my $root = $newdom->createElement('testsuites');
$newdom->setDocumentElement($root);
for my $file (@files) {
my $dom = XML::LibXML->load_xml(location => $file);
for my $node ( $dom->findnodes('//testsuite') ) {
$node->{name} =~ s/test_suite_name_/tsname_/;
$root->appendChild($node);
}
}
$newdom->toFile($outfile, 1);
With input files that look like this:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="test_suite_name_one">
<testcase name="test1" />
<testcase name="test2" />
</testsuite>
</testsuites>
It produces output like this:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="tsname_one">
<testcase name="test1"/>
<testcase name="test2"/>
</testsuite>
<testsuite name="tsname_two">
<testcase name="test3"/>
<testcase name="test4"/>
</testsuite>
<testsuite name="tsname_three">
<testcase name="test5"/>
<testcase name="test6"/>
</testsuite>
</testsuites>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.