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?
-
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.
|