How can i handle large number of XML files with perl script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crult
    New Member
    • Sep 2010
    • 1

    #1

    How can i handle large number of XML files with perl script?

    Hello,

    I have a large number of xml files in a folder. I want to read and extract the content of each xml file to a new.txt. I'm only interested in the content having the tag <Texte>, and i want to create a .txt file (a texte file for each of my xml's). I use the perl modules xml twig and xml simple. There's the code i have until now:

    Code:
    my $xml_dir="C:\xmlperl";
    my $output="C:\xmlperl\output.txt";
    my $file = $ARGV[0];
    
    opendir(DIR,$xml_dir) || die;
    
    my @TranscriptsList = grep(/xml$/, readdir(DIR));
    closedir(DIR);
    
    foreach $file (@TranscriptsList) {
    
    my $twig= new XML::Twig(TwigRoots => {Texte => 1});
    
    $twig->parsefile($file);
    
    $twig->print;
    
    open XMLOUT, '>>C:\xmlperl\output.txt';
    
    $twig->print(\*XMLOUT) or die;
    
    close XMLOUT;
    }
    As you can see, i can only print in a single .txt file the output of the xml content. Can you help me please?

    thank you in advance
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    That is because you have told it to append to only the one text file, the same one each time. You would need to find a way to have a unique file name if that is your decision. I don't want just give you an answer, it would be better if you found a way. If you truly get stuck and cannot figure it out we can throw you an idea, but I want to make sure you learn this.

    Regards,

    Jeff

    Comment

    Working...