Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:20:03+00:00 2026-05-27T02:20:03+00:00

I have multiple XML files in a folder,so I written script like this to

  • 0

I have multiple XML files in a folder,so I written script like this to combine into one xml file

#!/usr/bin/perl
use warnings;
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( my $allxml, '>', "all_xml_contents.combined.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-instance\">\n";
 my %shipto_md5;
find(
sub {
return unless ( /(_stc\.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( 'data' )) {
    my $elem = $reader->readOuterXml();
    my $md5 = md5( $elem );
    print $allxml $reader->readOuterXml() unless ( $shipto_md5{$md5}++ );
 }
 }
return;
}

It printing all xml files into one xml like this.

 all_xml.combined.xml
 <?xml version="1.0" encoding="UTF-8"?>
<student specification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <student>
<name>johan</name>
 </student>

<student>
<name>benny</name>
</student>

 <student>
<name>kent</name>
 </student>

 </student specification>

but I have one more node information in one xml file, i tried to extract that information like this in while loop.

    $reader->nextElement( 'details' );
     $information = $reader->readInnerXml();

but how can i add this information to output file, please help me with this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:20:04+00:00Added an answer on May 27, 2026 at 2:20 am

    Three obvious points.

    1. You’re loading the XML::LibXML module but not making any use of it.
    2. The problematic XML declaration is always the first line of the input files. So why not just skip the first line?
    3. The file you will end up with will not be valid XML. An XML document needs a single root element. So you’ll need to create another element (perhaps <students>) that surrounds all of the data from the other files.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder with multiple XML files. I need to bulk insert each
i have multiple Xml files, in a List<File> . What i want is to
I have a big xml file which is composed of multiple xml files. The
I have set up multiple targets in a single xml file. I expect all
I have an XML file (on the left) and I want to create multiple
I have a maven pom.xml file with multiple instances of a same goal defined
I have a folder structure that contains multiple javascript files, each of these files
I have a large application spread across multiple Spring bean definition xml files. In
I have been creating multiple background threads to parse xml files and recreate new
I have created an XML file in my solution path. My solution has multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.