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

  • SEARCH
  • Home
  • 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 7697111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:56:06+00:00 2026-05-31T21:56:06+00:00

I have a large xml file that looks like this: 20120124 07:30:15.301, saving to

  • 0

I have a large xml file that looks like this:

        20120124 07:30:15.301, saving to queue 
<logmessage>
    <logline1>some data</logline1>
    <logline2>some data too</logline2>
</logmessage>

    20120124 07:30:15.302, processing message 
<logmessage>
    <logline1>some data</logline1>
    <logline2>some data too</logline2>
</logmessage>

I want to split it into multiple files, each containing one logmessage, and I don’t want to keep any data outside the root node. How can I do this?

  • 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-31T21:56:07+00:00Added an answer on May 31, 2026 at 9:56 pm

    Be careful what you wish for. Consider the consequences of what you are doing. If this is a very large XML file as you have stated this will create a very large number of small files in your directory. That can be bad in many ways. Each will take up at least the smallest block size which can be large on todays massive filesystems. Each will take an inode on linux which is a finite resource, use df -i to determine if you have enough available. Finally some files systems have a limit or begin to perform poorly if too many files are created in the same directory.

    The following will tell you how many files will be created:

     perl -e '$/="</logmessage>";while(<>) {$i++};print $i,"\n"' log.xml
    

    The following will create a new file using the date and time for the file name with a .xml extension. If multiple messages have the same timestamp they will be appended.

    perl -e '$/="</logmessage>";while(<>) {m{([\d:\. ]+)};open(fh,">>","$1.xml");s{^.*?(?=<logmessage>)}{}sm;print fh $_,"\n";close fh}' log.xml
    

    Also be aware that many XML libraries will try to open the full file in memory which can be a problem for a very large xml file. This procedure will not attempt to open the whole file in memory. If your file is too large to fit in memory do not accept any solution that uses an XML parser that is not SAX or streaming. Using a DOM parser will require memory equal to your document size times a multiple for overhead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large XML file that looks like <data> skdfnlsniisimsoinfsdfoisdfinsdofinodnfonf <emrosem> 23324097234097g </emrosem>
I have an XML file that looks like this: <country> <routes> <SourceCountry>Ireland</SourceCountry> <SourcePort>Larne</SourcePort> <DestinationCountry>UK</DestinationCountry>
I have a log file that looks like the following: 2010-05-12 12:23:45 Some sort
I have an XML file that looks like: <sizes> <size name=original width=386 height=429> http://userserve-ak.last.fm/serve/_/62380831/Adele+PNG.png
So I have this pretty large XML file (40MB) that I'll have to repeatedly
I have a large XML file (many MBs) that I cannot afford to download
I have a request that returns a large xml file. I have the file
I have a very large XML file which has like 40000 data, and when
I have a large XML, looking like this: <gender>M</gender> <last-name>*</last-name> <profession>2165dda2-dc59-41af-acb5-06d8914c4841</profession> <first-name>*</first-name> <mail-confirmation>1</mail-confirmation> <fax-confirmation>1</fax-confirmation>
I have a function, that gets a large XML file, then parses it, and

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.