help need in the perl script that create one xml file form multiple files.


 
Thread Tools Search this Thread
Top Forums Programming help need in the perl script that create one xml file form multiple files.
# 1  
Old 11-18-2011
help need in the perl script that create one xml file form multiple files.

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>

Code:
      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.
Code:
           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.
Code:
    #!/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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tabbed multiple csv files into one single excel file with using shell script not perl

Hi Experts, I am querying backup status results for multiple databases and getting each and every database result in one csv file. so i need to combine all csv files in one excel file with separate tabs. I am not familiar with perl script so i am using shell script. Could anyone please... (4 Replies)
Discussion started by: ramakrk2
4 Replies

2. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

3. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

4. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

5. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

6. Shell Programming and Scripting

Create multiple zip files each containing 50 xml files.

Hi, Is there a direct command or need to write a shell script for following requirement? Everyday a folder is populated with approx 25k to 30k xml files. I need to create multiple zip files in the same folder each containing 50 xml files. The last zip file may or may not contain 50 xml files.... (6 Replies)
Discussion started by: Rakesh Thobula
6 Replies

7. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

8. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

9. Shell Programming and Scripting

How to create a xml file using Perl Script

Hi All, I have some data which needs to be saved in the xml file format.Can you guys please let me know how to do this using perl script. NOTE: the template of the xml file shall be depending on validation of the data done for some requirements. Basically to summarise, the fields in the xml... (5 Replies)
Discussion started by: girish.raos
5 Replies
Login or Register to Ask a Question