#!/usr/bin/perl use warnings; use strict; use XML::LibXML; use Carp; use File::Find; use File::Spec::Functions qw( canonpath ); use XML::LibXML::Reader; use Digest::MD5 'md5'; if ( @ARGV == 0 ) { push @ARGV, "c:/Main/work"; warn "Using default path $ARGV[0]\n Usage: $0 path ...\n"; } # open an output file whose name won't be found by File::Find open( my $allxml, '>', "all_xml_contents.combined1.xml" ) or die "can't open output xml file for writing: $!\n"; print $allxml '', "\n\n"; my %shipto_md5; find( sub { return unless ( /(_dtc\.xml)$/ and -f ); extract_information(); return; }, @ARGV ); print $allxml "\n"; sub extract_information { my $path = $_; if ( my $reader = XML::LibXML::Reader->new( location => $path )) { while ( $reader->nextElement( 'shipto' )) { my $elem = $reader->readOuterXml(); my $md5 = md5( $elem ); print $allxml $reader->readOuterXml() unless ( $shipto_md5{$md5}++ ); } } return; }