Getting outOfMemory while using Xpath for 6MB file

Hi ,
Requirement:
I have thousands of xml files of variable size (mostly around 5MB), Total size is around 20GB .The structure of xml content is as follows.
filename: xaaaa
<file>
<page>
<title>AmericanSamoa</title>
<id>6</id>
<revision>
<id>133452270</id>
<timestamp>2007-05-25T17:12:06Z</timestamp>
<contributor>
<username>Gurch</username>
<id>241822</id>
</contributor>
<minor />
<comment>Revert edit(s) by [[Special:Contributions/Ngaiklin|Ngaiklin]] to last version by [[Special:Contributions/Docu|Docu]]</comment>
<text xml:space="preserve">#REDIRECT [[American Samoa]]{{R from CamelCase}}</text>
</revision>
</page>
My task is to retrieve the ID , filename in which it exists and the position of node in the page, and i have to write it to a file.
ex: 6:xaaaa:1
My approach:
I am using Xpath for this. The code is as follows.
*/*XPathReader.java*/*
package preprocess;
import java.io.IOException;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class XPathReader {
private String xmlFile;
private Document xmlDocument;
private XPath xPath;
public XPathReader(String xmlFile) {
this.xmlFile = xmlFile;
initObjects();
private void initObjects(){       
try {
xmlDocument = DocumentBuilderFactory.
               newInstance().newDocumentBuilder().
               parse(xmlFile);
xPath = XPathFactory.newInstance().
               newXPath();
} catch (IOException ex) {
ex.printStackTrace();
} catch (SAXException ex) {
ex.printStackTrace();
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
public Object read(String expression,
               QName returnType){
try {
XPathExpression xPathExpression =
               xPath.compile(expression);
return xPathExpression.evaluate
               (xmlDocument, returnType);
} catch (XPathExpressionException ex) {
ex.printStackTrace();
return null;
XpathReaderTest.java
/* it takes directory name as argument, this directory contains xml file*/
package preprocess;
import java.io.*;
import javax.xml.xpath.XPathConstants;
import org.w3c.dom.*;
public class XPathReaderTest {
public XPathReaderTest() {
public static void main(String[] args) throws IOException{
     if (args.length <= 0) {
          System.out.println(
          "Usage: java PreProcess dir_name"
          return;
          String dir=null;
          if (args.length >= 1) dir = args[0];
          int indexno=0;
          File directory = new File(dir);
          File[] files = directory.listFiles();
          FileWriter fstream = new FileWriter("index"+indexno+".txt");
     BufferedWriter out = new BufferedWriter(fstream);
     XPathReaderTest xt=new XPathReaderTest();
          /*for (int index = 0; index < files.length; index++)
               System.out.println(files[index].toString());
          for (int index = 0,i=1; index < files.length; index++)
               /*if(index/100>indexno){
                    indexno++;
                    out.close();
                    fstream = new FileWriter("index"+indexno+".txt");
               out = new BufferedWriter(fstream);
               xt.extract(files[index].toString(),index,i,out);
               System.gc();
          out.close();
public void extract(String completepath,int index,int i,BufferedWriter out)
throws IOException
     System.out.println(index+" "+completepath);
          XPathReader reader = new XPathReader(completepath);
          String separator = File.separator;
          int pos = completepath.lastIndexOf(separator);
          String temp_fname=completepath.substring(0,pos);
          pos=temp_fname.lastIndexOf(separator);
          String f_name= completepath.substring(pos+1);
          i=1;
          while(true)
          String expression = "/file/page["+i+"]/id";
          String id_value= (String) reader.read(expression, XPathConstants.STRING);
          if(id_value=="")
               break;
          out.write( id_value + ":"+ f_name+ ":"+i+ "\n" );
i++;
Problem:
This code works fine for xml files < 6MB, but its giving outOfMemory for 6MB and above file.
I have tried with -Xms256m -Xmx512m option.
Please suggest the work around , or any modification to code that will resolve my problem.
I am new to java world , so problem root cause will be very helpful for me.
Thanks

Hi ,
Requirement:
I have thousands of xml files of variable size (mostly around 5MB), Total size is around 20GB .The structure of xml content is as follows.
/*filename: xaaaa*/
<file>
<page>
    <title>AmericanSamoa</title>
    <id>6</id>
    <revision>
      <id>133452270</id>
      <timestamp>2007-05-25T17:12:06Z</timestamp>
      <contributor>
        <username>Gurch</username>
        <id>241822</id>
      </contributor>
      <minor />
      <comment>Revert edit(s) by [[Special:Contributions/Ngaiklin|Ngaiklin]] to last version by [[Special:Contributions/Docu|Docu]]</comment>
      <text xml:space="preserve">#REDIRECT [[American Samoa]]{{R from CamelCase}}</text>
    </revision>
  </page>
</file>My task is to retrieve the ID , filename in which it exists and the position of node in the page, and i have to write it to a file.
ex: 6:xaaaa:1
My approach:
I am using Xpath for this. The code is as follows.
*/*XPathReader.java*/*
package preprocess;
import java.io.IOException;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class XPathReader {
    private String xmlFile;
    private Document xmlDocument;
    private XPath xPath;
    public XPathReader(String xmlFile) {
        this.xmlFile = xmlFile;
        initObjects();
    private void initObjects(){       
        try {
            xmlDocument = DocumentBuilderFactory.
               newInstance().newDocumentBuilder().
               parse(xmlFile);           
            xPath =  XPathFactory.newInstance().
               newXPath();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (ParserConfigurationException ex) {
            ex.printStackTrace();
    public Object read(String expression,
               QName returnType){
        try {
            XPathExpression xPathExpression =
               xPath.compile(expression);
            return xPathExpression.evaluate
               (xmlDocument, returnType);
        } catch (XPathExpressionException ex) {
            ex.printStackTrace();
            return null;
XpathReaderTest.java
/* *it takes directory name as argument, this directory contains xml file**/
package preprocess;
import java.io.*;
import javax.xml.xpath.XPathConstants;
import org.w3c.dom.*;
public class XPathReaderTest {
    public XPathReaderTest() {
    public static void main(String[] args) throws IOException{
         if (args.length <= 0) {
                System.out.println(
                 "Usage: java PreProcess dir_name"
                return;
          String dir=null;
          if (args.length >= 1) dir = args[0];
          int indexno=0;
          File directory = new File(dir); 
          File[] files = directory.listFiles();
          FileWriter fstream = new FileWriter("index"+indexno+".txt");
         BufferedWriter out = new BufferedWriter(fstream);
         XPathReaderTest xt=new XPathReaderTest();
          /*for (int index = 0; index < files.length; index++)
               System.out.println(files[index].toString()); 
          for (int index = 0,i=1; index < files.length; index++)
               /*if(index/100>indexno){
                    indexno++;
                    out.close();
                    fstream = new FileWriter("index"+indexno+".txt");
                   out = new BufferedWriter(fstream);
               xt.extract(files[index].toString(),index,i,out);
               System.gc();
          out.close();
    public void extract(String completepath,int index,int i,BufferedWriter out)
    throws IOException
         System.out.println(index+" "+completepath);
          XPathReader reader = new XPathReader(completepath);
          String separator = File.separator;
          int pos = completepath.lastIndexOf(separator);
          String temp_fname=completepath.substring(0,pos);
          pos=temp_fname.lastIndexOf(separator);
          String f_name= completepath.substring(pos+1);
          i=1;
          while(true)
          String expression = "/file/page["+i+"]/id";
          String id_value= (String) reader.read(expression, XPathConstants.STRING);
          if(id_value=="")
               break;
          out.write( id_value + ":"+ f_name+ ":"+i+ "\n" );
        i++;
}Problem:
This code works fine for xml files < 6MB, but its giving outOfMemory for 6MB and above file.
I have tried with -Xms256m -Xmx512m option.
Please suggest the work around , or any modification to code that will resolve my problem.
I am new to java world , so problem root cause will be very helpful for me.
Thanks

Similar Messages

  • "Cannot interpret data in file" error while using GUI_UPLOAD for .xls file

    Hi,
         I have made a program using FM GUI_UPLOAD to upload an .xls file to an internal table. But upon executing ,it gives error "Cannot Interpret data in file". I have seen in other posts people talking about GUI_UPLOAD FM to upload data from excel directly into internal table. Kindly help.
    Here is my code. I had tried using different combination for HAS_FIELD_SEPARATOR but still its not working.
    In my emp1.xls file , the data in each column is present in the same order as in the internal table. Although the first column in my internal table is NUMC. I dont know if that is causing the problem.
    REPORT  ZUPLOAD_1.
    data: itab TYPE TABLE OF zempl_master WITH HEADER LINE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = 'C:\empl1.xls'
        FILETYPE                      = 'ASC'
        HAS_FIELD_SEPARATOR           = 'X'
    *   HEADER_LENGTH                 = 0
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   CHECK_BOM                     = ' '
    *   VIRUS_SCAN_PROFILE            =
    *   NO_AUTH_CHECK                 = ' '
    * IMPORTING
    *   FILELENGTH                    =
    *   HEADER                        =
      TABLES
        DATA_TAB                      = itab.
    * EXCEPTIONS
    *   FILE_OPEN_ERROR               = 1
    *   FILE_READ_ERROR               = 2
    *   NO_BATCH                      = 3
    *   GUI_REFUSE_FILETRANSFER       = 4
    *   INVALID_TYPE                  = 5
    *   NO_AUTHORITY                  = 6
    *   UNKNOWN_ERROR                 = 7
    *   BAD_DATA_FORMAT               = 8
    *   HEADER_NOT_ALLOWED            = 9
    *   SEPARATOR_NOT_ALLOWED         = 10
    *   HEADER_TOO_LONG               = 11
    *   UNKNOWN_DP_ERROR              = 12
    *   ACCESS_DENIED                 = 13
    *   DP_OUT_OF_MEMORY              = 14
    *   DISK_FULL                     = 15
    *   DP_TIMEOUT                    = 16
    *   OTHERS                        = 17
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP at itab.
      write:/ itab-emp_no,itab-name.
    endloop.

    hi amber22 you need to use the below fm to upload an xls file
    FORM EXCEL_UPLOAD .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          FILENAME    = FILENAM
          I_BEGIN_COL = 1
          I_BEGIN_ROW = 1
          I_END_COL   = 6
          I_END_ROW   = 100
        TABLES
          INTERN      = xl_itab.
    * EXCEPTIONS
    * INCONSISTENT_PARAMETERS = 1
    * UPLOAD_OLE = 2
    * OTHERS = 3 .
      IF SY-SUBRC = 0.
    MESSAGE 'DATA UPLOADED SUCCESSFULLY' TYPE 'I'.
      ENDIF.
    ENDFORM.                    " EXCEL_UPLOAD

  • Ora 29534 while using loadjava for jar files

    I am trying to load activation/pop3/mail.jar in oracle 9.2.0.1 database.
    command : loadjava -user maxsb/maxsb@q71d -resolve -verbose -genmissing activation.jar
    but its giving me following error :
    resolving: class com/sun/mail/pop3/DefaultFolder
    errors : class com/sun/mail/pop3/DefaultFolder
    ORA-29534: referenced object MAXSB.com/sun/mail/pop3/POP3Store could not be
    resolved
    errors : class com/sun/mail/pop3/POP3Folder
    ORA-29534: referenced object MAXSB.com/sun/mail/pop3/DefaultFolder could not
    be resolved
    errors : class com/sun/mail/pop3/POP3Message
    ORA-29534: referenced object MAXSB.com/sun/mail/pop3/POP3Folder could not be
    resolved.....
    have already gave grant permissions to user..still giving me similar errors at the time of loading jar file nito oracle database.
    pl provide the solution..
    Kets

    Oracle is saying
    Cause: Name resolution determined that the indicated object is referenced but could not be resolved.
    Action: Correct name resolver or address resolution problems in the referenced class, or correct compilation problems in its source.
    -aijaz

  • Blank spaces while using GUI_DOWNLOAD for Chinese characters

    Hi,
    While using GUI_DOWNLOAD for chinese characters I have used a code page option of 8300 for Chinese.
    The file which is getting downloaded in a notepad has some Chinese characters coming under some headings.
    After that columns other columns are getting shifted towards the right.
    This is working correctly for English characters.
    Can someone please help me.
    Now I am using CL_GUI_FRONT_END_SERVICES=>GUI_DOWNLOAD.
    What special options should I pass now.
    Regards,
    Subhashini

    Hi,
    I only solved my problem by using different code pages 8400 and 8300 for Chinese and Taiwanese characters.
    I fixed the lengths of the fields by converting them to hexadecimal string and back to string using these function modules as below.
    DATA:lv_xstring TYPE xstring,
           lv_temp TYPE string.
      DATA: lv_conv TYPE REF TO cl_abap_conv_in_ce.
      lv_temp = p_name.
      CALL FUNCTION 'HR_KR_STRING_TO_XSTRING'
        EXPORTING
          codepage_to      = p_codepage
          unicode_string   = lv_temp
          out_len          = p_outlen
        IMPORTING
          xstring_stream   = lv_xstring
        EXCEPTIONS
          invalid_codepage = 1
          invalid_string   = 2
          OTHERS           = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
       EXPORTING
         from_codepage = p_codepage
         in_xstring    = lv_xstring
         out_len       = p_outlen
       IMPORTING
         out_string    = p_string.
    Create a Conversion Instance
    lv_conv = cl_abap_conv_in_ce=>create(
    encoding = p_codepage
    input = lv_xstring ).
    v_conv->read( IMPORTING data = p_string ).
    Regards,
    Subhashini

  • I am getting error while doing MFBF for semifinisg good

    Hi,
    i am getting error while doing MFBF for semifinisg good
    Existing standard cost estimate cannot be used
    Message no. RM175
    Diagnosis
    This error appears under the following circumstances:
    The existing standard cost estimate cannot be used for backflushing activities as the repetitive manufacturing profile was not maintained correctly when the standard cost estimate was carried out.
    The standard cost estimate must come from product costing. Other cost estimates (such as base object controlling) are not possible.
    Procedure
    The repetitive manufacturing profile assigned to the material at the time of the planned cost estimate must be a profile for repetitive manufacturing with product cost collector.
    Use product costing to create the standard cost estimate.

    I had already check REM profile repetitive mfg profile final backflush w. activities.
    this particular material is semifinish material attached in BOM of finish material.
    backflush of finish good is possible but now new requirement is to do production booking for the semifinish material.
    i had assign production version , done routing and maintain REM profile,
    created material cost with quantity structure ck11n then run the costing in ck40n.
    still getting the error what else is to done to able to book this thru MFBF.

  • What are the limitations in terms of data size  or performance while using csv or text file as datasource?

    <p>Also what are the limitations in terms of data size  or performance related issues while using csv or text file?</p><p>Is it the best practice to use csv , text file to use as a datasource to improve performance?</p><p>Please Advice.... </p><p>&#160;</p>

    <p>Hi,</p><p>Create Same Data Input for CSV and Text File ,Create 2 different reports one for CSV and One for Text ,run them one you have done that.</p><p>Go to Report Menu and Select Performance Information .Use the Data in that to check which one is good datasource to improve performance</p><p>Cheers</p><p>Rahul</p>

  • Getting error while using HTTP connector and calling POST action to a Web API which is deployed as website on Azure

    I have create Logic App under Azure App Services, I am getting
    error while using HTTP connector and calling POST action to a Web API which is deployed as website on Azure.
    Following are the screen shots:
    Login App Connector Diagram:
    hema

    Marking as answered since no response on request for more information - assuming that you found what was wrong in the inputs. Let us know if you're still having trouble.
    http://twitter.com/joshtwist

  • How to improve the load performance while using Datasources for the Invoice

    HI All,
    How to improve the  load performance while using Datasources for the Invoice . Actually my invoice load (Appx. 0.4 M records) is taking very long time nearly ~16 to 18 hrs  to update data from R/3 to 0ASA_DS01.
    If I load through flat file it will load with in ~20 Min for the same amount of data.
    Please suggest how to improve load performance.
    PS: I have done the Inpo package settings as per the OSS note.
    Regads
    Srininivasarao.Namburi.

    Hi Srinivas,
    Please refer to my blog posting [/people/divyesh.jain/blog/2010/07/20/package-size-in-spend-performance-management-extraction|/people/divyesh.jain/blog/2010/07/20/package-size-in-spend-performance-management-extraction] which gives the details about the package size setting for extractors. I am sure that will be helpful in your case.
    Thanks,
    Divyesh
    Edited by: Divyesh Jain on Jul 20, 2010 8:47 PM

  • Ipod touch 4 gets hot while using some apps like angry birds?

    Is it normal for the upper back of the ipod touch 4 to get hot while using some apps like angry birds? Is this a potential battery problem? It doesnt get hot while charging or playing songs... Just when using some game apps.  I assume that it has something to do with battery drain, should I be concerned?

    When the iPod is used heavily like for games it is norma for the iPod to get warm.  Unless you hav short battery life I would not be concerned.

  • Framemaker uses $filename for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen?

    Framemaker uses <$filename> for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen? In compiling our books it would be helpful to not have this extension appear as it then requires us to create extra files without them.

    See: System Variables

  • Sender file adapter - Can I use *.xml for the file name

    Hi Gurus,
    I have some interfaces where I need to pick the file from a directory. The name of the file will have Data<i>time stamp</i> as the naming convention. Can I use *.xml to pick up my files from this directory?
    The help.sap.com documentation says that we can use this naming convention.
    <b>
    &#9679;      File Name
    Specify the name of the file that you want to process. The name can contain placeholders (*, ? (placeholders for exactly one character)) so that you can select a list of files for processing.
    </b>
    I tried using *.xml for my file name in the communication channel, XI is not picking up this file.
    Please let me know if you have the solution.
    Thanks
    Kalyan

    Murthy,
    Thanks for the reply.
    I am using GuildFTP tool as my FTP server. In this tool, all the permissions were given for the file to pick up.
    The status of the file is good.
    Where in the file adapter configuration I have to select 'Read-only'?
    The file adapter is working perfect with the exact name of the file.
    Thanks
    Kalyan

  • Is it common that iPhone purchased in other Country may get heated while using 3G network ?

    Is it common that iPhone purchased in other Country may get heated while using 3G network ?
    My iPhone5 gets heated when I am on 3G Network and this device is purchased in another country which I am not a Resident-of.
    Please assist. Thanks !

    About ControlPlane

  • My iphone 5 gets hot while using it and while charging too.... Please help me what should i do?? Should i replace the battery....??  Because it gets hot even within 5 minutes also....  And it is happening from 2 weeks daily.

    My iphone 5 gets hot while using it and while charging too.... Please help me what should i do?? Should i replace the battery....??  Because it gets hot even within 5 minutes also....  And it is happening from 2 weeks daily.

    The Basic Troubleshooting Steps are:
    Restart... Reset... Restore from Backup...  Restore as New...
    Restart / Reset   >  http://support.apple.com/kb/ht1430
    Backing up, Updating and Restoring  >  http://support.apple.com/kb/HT1414
    If you try all these steps and you still have issues... Then a Visit to an Apple Store or AASP (Authorized Apple Service Provider) is the Next Step...
    Be sure to make an appointment first...

  • I have 5s and is getting heat while using it and durin charging

    I have 5s 7.0.4 (64G) and is getting heat while using it and durin charging

    thanks dear friend,
    but from Apple - Batteries - Notebooks:
    Apple does not recommend leaving your portable plugged in all the time !!!
    it's opposite of what you saying !

  • IPad is getting heat while using skype

    Hi
    Please advice me a solution, my iPad is getting heat while using skype.
    Thanks
    Satya

    do not use anyother app while you are using skype , its not your software fault problem is regarding to your device,physically check your device from where you bought it

Maybe you are looking for

  • Doubt with Iview Team Calendar

    Dear I have the following issue. The system in the iview Team Calendar is showing an employee that are not to the Organizational Unit of the Boss. The employee "Jorge" had a organizational change from 23.08.2011. In the iview Team General Information

  • E6-00 strange sound and 3g traffic

    Hi. I have a problem with my E6. On standby from time to time (i think 1hour or more) it make a strong beep and then the 3g transfer icon appear. It stays like this for 6-7 sec then the 3g connection close itself. There is no running program in the b

  • Reg:hr anlytics informatica mapping

    I have one more question.the out of the box mappings calculates age of every person on first of every month.If a person has birth day in the middle of the month,it doesnot calculate and the person is still one year younger though he passed his birthd

  • Deselect radial button in shut down as default

    When I shut down I would prefer to have the "open windows on restart" radial button deselected.  How is this done?  In the console?  Some preference somewhere?

  • Panther G4 AGP won't boot for anything!

    At our school we have 10 G4 macs. One was working, but as of July it has been dead. For some reason the grey apple at bootup sits forever. It was running panther. I tried to boot off a panther CD and no go. Only a OS 9.1 disk will boot, but after sho