Hi every one,
Please excuse me if any grammatical mistakes is there.
I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p>
file1:bvr.xml
<?xml version="1.0" encoding="UTF-8"?>
<specification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<details>
<name>johan</name>
<address>Langgt 23</address>
---more info---
</details>
</specification>
file2:kvr.xml
<?xml version="1.0" encoding="UTF-8"?>
<shiporder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<details>
<name>venu</name>
---more info---
</details>
</specification>
file3:svr.xml
<?xml version="1.0" encoding="UTF-8"?>
<shiporder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<details>
<name>kent</name>
---more info----
</details>
</specification>
file4:tvr.xml
<?xml version="1.0" encoding="UTF-8"?>
<shiporder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<definition>
<name>kent</name>
----more info---
</definition>
</specification>
I need to create one xml file like this.
new.xml
<?xml version="1.0" encoding="UTF-8"?>
<specification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<details>
<name>johan</name>
<address>Langgt 23</address>
--more info--
</details>
<details>
<name>venu</name>
---more info----
</details>
<details>
<name>kent</name>
<address>vadrss 25</address>
---more info--
</details>
<definition>
<name>kent</name>
----more info----
</definition>
</specification>
I tried like this But I have some problems with this script.
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
use XML::LibXML::Reader;
use Data::Dumper;
my $Number;
my $dir="C:/file/sav";
find(\&wanted, $dir);
sub wanted() {
if ( -f and /(\.xml)$/) {# find all the files with a suffix of .xml
my $reader = XML::LibXML::Reader->new( location =>$_ )
or die "cannot read file.xml\n";
while ($reader->nextElement( 'details' ) ){
$Number = $reader->readOuterXml();
print "$Number\n";
}
}
return;
}
but I have two problem in this script
1) I am extracting information from all XML files Having "details" Node element, But in one XML file I have data with some other Node element "definition" I am not extracting that information, What should I do if I want to extract that information and store in the same variable.
2) After extracting all information That is stored in a $Number varible, I want to store that $Number variable information in one XML file how can I do that one. Please help me.I am very new to perl.
\(or\)
Is there any other ways to combined all XML files data into one XML file.