Loading LOTS of objects from xml

hi
I'm developing code that parses an XML file with known elements and reads the contents into objects
I've been doing this using DOM
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource in = new InputSource(xmlFile);
Document doc = db.parse(in);The trouble is that when I test reading in of over 6000 objects, I'm getting
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeObject(DeferredDocumentImpl.java:1000)
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.synchronizeChildren(DeferredDocumentImpl.java:1741)
at com.sun.org.apache.xerces.internal.dom.DeferredElementImpl.synchronizeChildren(DeferredElementImpl.java:132)
at com.sun.org.apache.xerces.internal.dom.ParentNode.hasChildNodes(ParentNode.java:194)
at com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl.nextMatchingElementAfter(DeepNodeListImpl.java:168)
at com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl.item(DeepNodeListImpl.java:143)
at com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl.getLength(DeepNodeListImpl.java:114)
at business.PersonRegister.persist(PersonRegister.java:247)
at business.PersonRegister.main(PersonRegister.java:807)
I believe this is because there is insufficent memory to read the whole Dom document in before parsing...?
Creating the objects and using them in memory is not a problem - it's much quicker than a SQL database, but I need a way of reading the XML file without first creating the entire DOM document.
There must be a way of reading and parsing one element, creating the object, reading and parsing, creating and so on to save loading up the whole DOM document
has anyone got any bright ideas please?

thanks for both the replies above - essentially the same correct solution.
something worth noting now that I've written and tested both a SAX solution and a DOM solution is that there is a significant (4 x) time penalty using SAX.
I considering dividing the vector I am storing/recovering into chunks and saving each chunk separately using DOM to speed things up...
any thoughts on this approach?

Similar Messages

  • I want to load a sales order from xml file. How can I do.

    Hi,
    I want to load a sales order from XML  file. How can I do ? how can i create the sales order?
    what are the necessary  setting for  create the sales orders.
    with Regards,
    Prakesh.

    Three options come to my mind.
    Option 1: Use SAP transaction SXDA_TOOLS (Object Type BUS2032), Program Type (BAPI) and Program (CREATEFROMDAT2).
    Option 2: Use SAP transaction SXDA_TOOLS (Object Type BUS2032), Program Type (DINP) and Program (RVINVB10).
    Option 3: Translate the xml to IDoc so that ORDER04 / ORDER05 Idoc can be used to create Sales order (WEDI transaction).

  • Load business partner (supplier ) from XML

    Hi ,
    I have two similar sap companies demo1 and demo2  I need to copy supplier object ( business partner object with  cardType = supplier  )   from demo1 company to demo2 company. To perform this action i am using code below
    ''''' code to save bp object as xml
    Dim oBP As SAPbobsCOM.BusinessPartners = clsGlobals.SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)
    clsGlobals.SBOCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode
    oBP.GetByKey("bp1")
    oBP.SaveXML("c:\bp1.xml")
    '''' code to load bp object from xml (after connenct to demo2 company)
    Dim oBP As SAPbobsCOM.BusinessPartners = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)
    oBP = m_diCompany.GetBusinessObjectFromXML("c:\bp1.xml", 0)
    If oBP.Add() <> 0 Then
          Throw New Exception(oCompany.GetLastErrorDescription)
    i got exception " You cannot set the field if business partner is a vendor "
    Very important note : with bp object with cardType = customer this code working fine
    If any one can help us with this problem?
    Thanks.

    Thanks for all answers ,
    I resolved this issue by adding new bp as supplier , after that i updated the bp from xml .
    source code:
    m_diCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode
                        Dim oBP As SAPbobsCOM.BusinessPartners = m_diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)
                        oBP.CardCode = m_newCardCode
                        oBP.CardType = SAPbobsCOM.BoCardTypes.cSupplier
                        If oBP.Add() <> 0 Then
                            GlobalDll.log.writeToLog("add bp err with cod:" & m_newCardCode & " to db with name:" & check.Caption)
                            errFlag = True
                            sapErr = m_diCompany.GetLastErrorDescription
                            Throw New Exception(sapErr)
                        End If
                        If oBP.UpdateFromXML(xmlFilePath) <> 0 Then
                            GlobalDll.log.writeToLog("update from xml bp err with cod:" & m_newCardCode & " to db with name:" & check.Caption)
                            errFlag = True
                            sapErr = m_diCompany.GetLastErrorDescription
                            Throw New Exception(sapErr)
                        End If
                        If oBP.Update() <> 0 Then
                            GlobalDll.log.writeToLog("update  bp err with cod:" & m_newCardCode & " to db with name:" & check.Caption)
                            errFlag = True
                            sapErr = m_diCompany.GetLastErrorDescription
                            Throw New Exception(sapErr)
                        Else
                            File.Delete(xmlFilePath)
                            GlobalDll.log.writeToLog("bp with cod:" & m_newCardCode & " was added to db with name:" & check.Caption)
                        End If

  • Dynamically create Value Objects from XML file

    Hi
    I want to create a value object from Xml file dynamically,like in the xml file i have the name of the variable and the datatype of the variable.is it possible do that,if so how.

    Read about apache's Digester tool. This is part of the Jakartha project. This tool helps in creating java objects from the XML files. I am not sure, if that is what u r looking for.

  • Load object from xml

    Imagine if you can that I have a XmlLoader class for each object that can be loaded from xml.
    Before I had the xmlLoader code inside the objects but it's better to separate loading from actual object...
    these xmlLoaders needs to be able to set all vars for those objects. How would be the best way to do that?
    Atm I have made all vars with a package scope. but this really opens the object open to all other objects in that package...
    I don't know any other options. so how do you keep your vars safe, but still be able to load them from whatever source(xml, txt)...?

    Apache Digester is good for this sort of thing. It uses setter methods to populate your objects. You could also just use XML Serialization and deserialization. Or, you could go for something like JAXB or XMLBeans, whereby you actually will have classes generated for you from XML Schemas, and instances of those classes can marshall and unmarshall themselves quite easily

  • Sqlldr is loading only 1st record from xml document

    Hi,
    I am trying to load XML doc with multiple records using sql*loader.
    I have registered my XSD perfectly.
    This is my control file
    LOAD DATA
    INFILE *
    INTO TABLE Orders APPEND
    XMLType(xmldata)
    FIELDS(
         xmldata LOBFILE (CONSTANT FULDTL_2.xml)
    TERMINATED BY '???')
    BEGINDATA
    FULDTL_2.xml
    -- Here, what I have to give for TERMINATED BY '???'
    My xml doc
    <Order ID="146120486" Status="CL" Comments="Shipped On 08/05/2008"/>
    <Order ID="143417590" Status="CL" Comments="Handset/Device has been received at NRC" ShipDate=""/>
    sqlldr is loading only 1st record from the file.
    How can I make it to load all the records from my xml doc.
    Thanks in advance.

    thanks for both the replies above - essentially the same correct solution.
    something worth noting now that I've written and tested both a SAX solution and a DOM solution is that there is a significant (4 x) time penalty using SAX.
    I considering dividing the vector I am storing/recovering into chunks and saving each chunk separately using DOM to speed things up...
    any thoughts on this approach?

  • Create value object from xml

    So I've got a value object with 100 fields.
    I have a ASP.net web service that returns the value objects
    as XML (I really don't want to use WebOrb...).
    I don't want to write a lot of code like this:
    vo.Field1 = voXML.Field1;
    vo.Field2 = voXML.Field2;
    vo.Field3 = voXML.Field3;
    Is there an easier/faster way to do this? Can't I do some
    sort of for/each loop. The element names are identical to the field
    names.
    Thanks.

    http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=usingas_053_9.html#220936

  • How to load images in List from Xml and view the image and resize the image & save in Flex?

    Hi Friends,
    I am new to flex i am doing application for image resizing rotating and save the resize image.
    I want to load the images from xml file to listcontrol and show that images as a icon in the listview,then i want to drag that image to panel that time it should show it original size of the Image.then it allows user to resize ,crop,rotate the image.then i want to save the resize image,when i save the resize image it should replace the original image in the xmllist.
    I am looking for some useful suggession ,if you dont mind want to see some snippet code.
    It will help me to understand the concept.
    Cheers,
    B.Venkatesan

    Not in Crystal Reports Basic for Visual Studio 2008. You'll have to upgrade to CR 2008 (12.x). Then use kbase [1320507|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do] as a guide on how to do this.
    Ludek

  • Delta load of customizing objects from R3 to CRM

    I need to set up a delta load for customizing objects for ex: DNL_CUST_BNKA from R3 to CRM.  Is there any documentation on this subject?  Please advise.  Thanks.

    This is what I got from SAP
    Bank Details information is a customizing object, and is not designed
    for frequent changes, because there's no delta download for customizing
    objects. If you create new Bank/change detail or delete an old one,
    you have to perform initial load manually for DNL_CUST_BNKA again.
    You can also do a request download of the replication object
    'DNL_CUST_BNKA'to get some bank data added later on.
    (Transaction \R3AR2 ).
    You will need to do a request download of bank data from time to time
    whenever you change the bank details. This is currently how it can be
    done in SAP Standard.
    If you change regularly bank master data:
    The data has to be in sync between R/3 and CRM. If you make changes
    often to the bank master data, you might consider scheduling a regular
    job. See below for steps.
    1. Transaction R3AS
    2. Load Object = DNL_CUST_BNKA
    Source Site = your R/3 system
    Destination Site = your CRM system
    3. Menu Goto > Variants > Save Variant
    4. Enter a Variant Name and Description
    5. Start Transaction SM36 to define a background job
    6. Select the Job Wizard button:
    In step Defining a Job Step, select ABAP program step
    In step Define an ABAP Program Job Step, enter ABAP program name
    SMOF_DOWNLOAD and the variant you created in step 4
    7. Click on Job Wizard and follow the steps, choose ABAP Program
    SMOF_DOWNLOAD and the variant you created in step 4
    8. Select start time Immediately
    9. Press Complete to finish
    10.Choose Job Selection (SM37)
    11.Enter the Job Name -> should have status finished
    Schedule the job (SM36 > start condition) according to how often you
    change your bank

  • How To Generate Objects From XML and DTD?

    Are there tools to generate objects from dtd's and xml files?
    If this is not possible for some reason: is there a tool to generate classes from a dtd?
    I can not find the "XML Java Class Generator" (from oracle) anymore.

    XMLBeans
    There are other solutions, but I know this one is pretty good.

  • How to create value objects from xml

    I am receiving xml back from my web service ( e4x ). I am
    trying to figure out how to create a value object without having to
    manually fetch each value in the value objects constructor. I am
    using introspecton in my Java web service to do this. Is there such
    a thing in Action Script?
    Anyone done this before that can share some code???? Any help
    would be very much appreciated.

    That's twice now I've heard that. lol.
    I am using Cairngorm and I suppose out of ignorance perhaps,
    I am using VO's. So my web service would return an Object Proxy and
    I have some code that could create objects dynamically from the
    results. The objects had to be simple of course and now they are
    becoming more complex thus the need to change to e4x instead of
    objects.
    So now I am trying to convert the xml result into the desired
    VO to be used throughout the rest of the application. I'm not sure
    how to use Cairngorm without the VO's they are tied to everything.
    Are you familiar with the architecture? Your thoughts?

  • Partially populating an object from XML data

    I have an unpopulated object which I intend to fill on-demand by grabbing several XML files via HTTP.
    I'm not sure how best to deal with this in Java - at present I keep a set of booleans to describe what information is present, and update these as I grab new data by parsing the XML
    Is there a way I can better use the object oriented features of Java to manage this?
    cheers,
    Jon

    Hi there again,
    Do you have zmaterial on your InfoSource? And in your InfoCube?
    If so, you only need zcolour in the Infocube and the way you're doing is correct. In the rule of the zcolour you can select master data attribute of and from the list it should appear all the InfoObjects that exist on the InfoSource that has zcolour as an attribute, in this case, zmaterial.
    If before you select the list of the InfoObjects available on the master data attribute of you click on F1 you see the help that says exactly that (and I have done it tones of times):
    Master data attrib.
    The specified characteristic has the characteristic to be updated as an attribute.
    With this setting, the value of the characteristic to be updated is read in the master data table of the specified characteristic.
    Example
    The Characteristic 'Material Group' is not delivered through the InfoSource.
    The characteristic 'Material' is delivered through the InfoSource.
    The characteristic 'Material' has the characteristic 'Material Group' as an attribute.
    You can fill 'Material Group' through the master data table 'Material'. To do this select the method 'Master Data Attribute from' and 'Material' as source.
    Regards,
    Diogo.

  • Load hyperlink into image from xml

    Hello everyone,
    I am completely new to Flex and got stuck with this problem:
    I would like to put a hyperlink into an image, both are loaded from external xml
    xml looks like this:
          <project>
          <id>0</id>
          <titel>project google</titel>
          <image>image1.gif</image>
          <url>www.google.com</url>
          <date>06/01/2008</date>
          <description>Some description</description>
        </project>
    So the url needs to be put into image 1
    Hope someone can help me out...
    Thanks in advance!

    how is the XML loaded in? via PHP? or a static XML file.
    if it's a static XML file, you'll have to load it in, feed it to an XML List collection and then simply feed the correct node to the image source.
    they do this kind of thing here:
    http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tile list-control/
    if it's loaded in via PHP, you'll need to handle the HTTPService request, and feed the image source an item off the result event.

  • Create file object from xml file in different package

    I have my java class which is in a package...edu.xx.proj
    It contains the following
    File f = new File("formats.xml");
    My xml file is in the package edu.xx.proj.xml
    How do I get the file object for my xml file?
    Ultimately I want that once the jar is shipped .. The path of xml file shld be independent of my OS path... it can only lookup the package path..
    I will really appreciate it if someone can throw some input as to how to resolve this issue..
    Thank you

    I have my java class which is in a
    package...edu.xx.proj
    It contains the following
    File f = new File("formats.xml");
    My xml file is in the package edu.xx.proj.xml
    How do I get the file object for my xml file?
    Ultimately I want that once the jar is shipped .. The
    path of xml file shld be independent of my OS path...
    it can only lookup the package path..
    I will really appreciate it if someone can throw some
    input as to how to resolve this issue..
    Thank you
    InputStream inputStream = getClass().getResourceAsStream("xml/formats.xml");
    /* OR */
    URL url = getClass().getResource("xml/formats.xml");hth

  • Create java objects from xml

    I want to create a tree structure for java object. These java objects are populated after the parsing the xml. But what could be the logic for adding child to parent when there are
    many sub nodes? I wanted to use one recursive function which iterate through all the elements of the xml file. But I have not got the idea how to add one child object to parent object.
    following are my classes. Any help on this highly appreciated.
    public class TreeObject {
              private String name;
              private TreeParent parent;
              public TreeObject(String name) {
                   this.name = name;
              public String getName() {
                   return name;
              public void setParent(TreeParent parent) {
                   this.parent = parent;
              public TreeParent getParent() {
                   return parent;
              public String toString() {
                   return getName();
    import java.util.ArrayList;
    public class TreeParent extends TreeObject {
         private TreeObject treeObject ;
              private ArrayList children;
              public TreeParent(String name) {
                   super(name);
                   children = new ArrayList();
              public void addChild(TreeObject child) {
                   children.add(child);
                   child.setParent(this);
                   treeObject = child ;
              public void removeChild(TreeObject child) {
                   children.remove(child);
                   child.setParent(null);
              public TreeObject [] getChildren() {
                   return (TreeObject [])children.toArray(new TreeObject[children.size()]);
              public boolean hasChildren() {
                   return children.size()>0;
              public TreeObject getChild(){
                   return treeObject;
    private TreeParent getChilderen(Element rootNode){
         List list = rootNode.getChildren();
         String rootNodeName = rootNode.getName();
         TreeParent root = new TreeParent(rootNodeName);
         for (int i=0; i< list.size(); i++)
    Element node = (Element) list.get(i);
    if(node.getChildren().size() > 0){
         // TreeParent treeParent = new TreeParent(node.getText());
         TreeParent treesub = new TreeParent(node.getText());
         treesub.addChild(treesub);
         //TreeParent p = treeParent.getParent();
         // rootParent.addChild(treeParent);
    }else{
         TreeObject object = new TreeObject(node.getText());
         root.addChild(object);
    getChilderen(node);
         return root ;
    public TreeParent buildTree(String filePath) {
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(filePath);
    try{
    Document document = (Document) builder.build(xmlFile);
    Element rootNode = document.getRootElement();
    // List list = rootNode.getChildren("staff");
    TreeParent rootParent = getChilderen(rootNode);
    return rootParent ;
    }catch(IOException io){
    System.out.println(io.getMessage());
    }catch(JDOMException jdomex){
    System.out.println(jdomex.getMessage());
    return null;
    Edited by: 870611 on Jul 6, 2011 6:27 AM

    Hi
    I recommend you use the API JAXB. Is much simpler.
    here a link: http://www.oracle.com/technetwork/articles/javase/index-140168.html
    here a example: http://download.oracle.com/javaee/5/tutorial/doc/bnbay.html#bnbbc

Maybe you are looking for