jyo has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I am Sorry for asking this question because I got some help form this site but I am struggling with this problem.
#!/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 '<?xml version="1.0" encoding="UTF-8"?>', "\n<Shiporder xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instanc +e\">\n"; my %shipto_md5; find( sub { return unless ( /(_dtc\.xml)$/ and -f ); extract_information(); return; }, @ARGV ); print $allxml "</Shiporder>\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; }
In the above script by using md5, its deleting repeated node having same data, but if some files have repeated elements in the node by searching repeated one element how to remove total node information. help me with this problem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem With adding node information to xml files.
by Anonymous Monk on Nov 21, 2011 at 17:44 UTC | |
by jyo (Initiate) on Nov 21, 2011 at 20:33 UTC | |
by Anonymous Monk on Nov 23, 2011 at 07:29 UTC | |
by jyo (Initiate) on Nov 23, 2011 at 08:17 UTC | |
|
Re: problem With adding node information to xml files.
by Anonymous Monk on Nov 21, 2011 at 17:35 UTC |