Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Conatenating XML files

by un-chomp (Scribe)
on Jul 30, 2007 at 15:08 UTC ( [id://629587]=note: print w/replies, xml ) Need Help??


in reply to Concatenating XML files

XML::LibXML to the rescue (again):
#!/usr/bin/perl use strict; use warnings; use File::Find::Rule; use XML::LibXML; # get a list of target files my $input_folder = 'input'; # whatever my @files = File::Find::Rule->file->in( $input_folder ); # initiate XML parser my $parser = XML::LibXML->new; $parser->expand_entities( 0 ); # leave entities alone # go through target files, collecting elements of interest my @wanted; foreach my $file ( @files ) { # parse XML my $dom = $parser->parse_file( $file ); # input # select and store all top level elements push @wanted, $dom->documentElement->findnodes( './*' ); } # make a new document my $new = XML::LibXML::Document->new( '1.0', 'UTF-8' ); # add root element my $root = XML::LibXML::Element->new( 'xml' ); $new->addChild( $root ); # add the inner elements we've collected $root->addChild( $_ ) for @wanted; # output print $new->toString;

Replies are listed 'Best First'.
Re^2: Conatenating XML files
by moritz (Cardinal) on Jul 30, 2007 at 15:51 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://629587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-24 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found