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 8620623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:37:28+00:00 2026-06-12T06:37:28+00:00

I need to extract XMLs from a huge (around 500mb) file but I have

  • 0

I need to extract XMLs from a huge (around 500mb) file but I have a 32bit JVM which always runs out of heap space.

I have written a program to extract XMLs from this file but to do that the whole file has to be read (I can not go with 100 lines or so per iteration, as I can not make sure the 100th line would be the end of an XML).

SO how do I do it?

My program for extraction:

private static ArrayList<String> extractXml(String xml) {
    String[] newXml = xml.split("\\<\\?");
    ArrayList<String> xmlList = new ArrayList<String>(Arrays.asList(newXml));
    for(int i = 0; i<xmlList.size();i++){
        if(!xmlList.get(i).contains("xml version=\"1.0\" encoding=\"UTF-8\"")){
            xmlList.remove(i);
        }
    }
    int size = xmlList.size();
    if(xml.contains("#"))
    for(int j = 0;j<size;j++){
        xmlList.set(j, "<?"+xmlList.get(j));
        xmlList.set(j,xmlList.get(j).split("\\#")[0]);

    }else
        for(int j = 0;j<size;j++){
            xmlList.set(j, "<?"+xmlList.get(j).trim());
            System.out.println(xmlList.get(j));             
        }



    return xmlList;

}

The XMLs also have a Header (its a JMSStream header. Like a wrapper on the XML) which I have been successfully removing using above logic.

Sample file content:

#---------- #2 : ID:QADC1_HGR1-EMS13112.15DB4FBEA3665328B:4985 ----------#
<MSG_INFO>
    <message type="TextMessage" messageSelector="" receiveTime="2012-09-12T14:37:26.717" jmsServerTimestamp="2012-09-12T14:37:26.775">
        <header JMSMessageID="ID:QADC1_HGR1-EMS13112.15DB4FBEA3665328B:4985" JMSDestination="OPS.FPES.OUTBOUND.FLIGHT.TRACK_A.DISTRIBUTION" JMSDestinationType="Topic" JMSDeliveryMode="2" JMSPriority="4" JMSTimestamp="1347478646775"/>
        <properties>
            ...
        </properties>
    </message>
</MSG_INFO>
BodyLength=31108
<?xml version="1.0" encoding="UTF-8"?>

<ns0:Envelope xmlns:ns0="http://www.wnco.com/opsplatform/flight/flightevent">
    <ns0:Header>
        <ns1:EventHeader xmlns:ns1="http://www.wnco.com/opsplatform/event/header">
            ...
        </ns1:EventHeader>
    </ns0:Header>
    <ns0:Body>
        <ns1:Flight xmlns:ns1="http://www.wnco.com/opsplatform/flight/flight">
           <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                ...
                <ns3:OperationalFlightLeg xmlns:ns3="http://www.wnco.com/opsplatform/flight/flight/operationalflightleg">
                    ...
                </ns3:OperationalFlightLeg>
            </ns2:ScheduledFlightLeg>
            <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                ...
                    ...
                </ns3:OperationalFlightLeg>
            </ns2:ScheduledFlightLeg>
            <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
               ...
                    ...
                </ns3:OperationalFlightLeg>
            </ns2:ScheduledFlightLeg>
            <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                ...
                    ...
                </ns3:OperationalFlightLeg>
            </ns2:ScheduledFlightLeg>
        </ns1:Flight>
    </ns0:Body>
</ns0:Envelope>

#---------- #3 : ID:QADC1_HGR1-EMS13112.15DB4FBEA3665328B:4985 ----------#
        <MSG_INFO>
            <message type="TextMessage" messageSelector="" receiveTime="2012-09-12T14:37:26.717" jmsServerTimestamp="2012-09-12T14:37:26.775">
                <header JMSMessageID="ID:QADC1_HGR1-EMS13112.15DB4FBEA3665328B:4985" JMSDestination="OPS.FPES.OUTBOUND.FLIGHT.TRACK_A.DISTRIBUTION" JMSDestinationType="Topic" JMSDeliveryMode="2" JMSPriority="4" JMSTimestamp="1347478646775"/>
                <properties>
                    ...
                </properties>
            </message>
        </MSG_INFO>
        BodyLength=31108
        <?xml version="1.0" encoding="UTF-8"?>

        <ns0:Envelope xmlns:ns0="http://www.wnco.com/opsplatform/flight/flightevent">
            <ns0:Header>
                <ns1:EventHeader xmlns:ns1="http://www.wnco.com/opsplatform/event/header">
                    ...
                </ns1:EventHeader>
            </ns0:Header>
            <ns0:Body>
                <ns1:Flight xmlns:ns1="http://www.wnco.com/opsplatform/flight/flight">
                   <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                        ...
                        <ns3:OperationalFlightLeg xmlns:ns3="http://www.wnco.com/opsplatform/flight/flight/operationalflightleg">
                            ...
                        </ns3:OperationalFlightLeg>
                    </ns2:ScheduledFlightLeg>
                    <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                        ...
                            ...
                        </ns3:OperationalFlightLeg>
                    </ns2:ScheduledFlightLeg>
                    <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                       ...
                            ...
                        </ns3:OperationalFlightLeg>
                    </ns2:ScheduledFlightLeg>
                    <ns2:ScheduledFlightLeg xmlns:ns2="http://www.wnco.com/opsplatform/flight/flight/scheduledflightleg">
                        ...
                            ...
                        </ns3:OperationalFlightLeg>
                    </ns2:ScheduledFlightLeg>
                </ns1:Flight>
            </ns0:Body>
        </ns0:Envelope>
  • 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-06-12T06:37:30+00:00Added an answer on June 12, 2026 at 6:37 am

    Using JAVA Scanner to extract the XMLs based on a unique property per XML.

     public static void main(String[] args) {
          String temp = null;
          String searchedData = null;
          File file = new File(fileLocation);
          try{
                Scanner scan = new Scanner (file);
                scan.useDelimiter("xml version");
                while (scan.hasNext()){
                      temp = scan.next();
                      if(temp.contains("<ns1:EventCorrelationID>153721264</ns1:EventCorrelationID>")){
                            searchedData = temp.substring(0, temp.lastIndexOf("</ns0:Envelope>")+15);
                            System.out.println("xml version"+searchedData);
                      }
                }
          }catch(Exception e){
                e.printStackTrace();
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to extract .co.uk urls from a file with lots of entries, some .com
I need to extract a value from a hidden HTML field, have somewhat figured
I need to extract the following data from a txt file(displayed in link),then save
I need to extract the text from the nodes in an html file and
I need to extract the video names from youtube's index.html. I have been able
I need to extract parts of a dataframe, using the values which I have
I need to extract a value from a process array to myArray: File: MyClass.vb
I need to extract/crop the logotype (BEAVER) in the middle from a TIFF file
I need to extract just the filename (no file extension) from the following path....
I need to extract data from xml file and plot graphs of: depth vs

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.