>
> Hi,
>
> I am working on a task where i need  to parse a large xml file (230  MB)
> and need to save into database. All the values are attributes so i am using
> the  below code to parse  and pull out attributes from child nodes and then
> save it using hibernate session.save and as  they are part of content and
> are not accesible to hibernate mapping if i put the direct
> path(//childelement/@attribute)



> Is the below correct/best way? of doing it for now its working fine but for
> large no of rows it  slows down considerably even though initially its runs
> very fast  5k per min
> After going thru some threads i doubt if its the detach method that is
> taking up time and memory or may be since i am adding up all the attributes
> to the root element is that causing te spike in javax memory
> Please let me know your thoughts.
>
> public class ParseLargeXML {
>
>         public static void main(String args[])
>         {
>                 try
>                 {
>
>                         ParseLargeXML plXML = new ParseLargeXML();
>                          plXML.parseLargeXML();
>         }
>
>            protected List loanList = null;
>         protected Session dom4jSession;
>         protected Session session;
>         protected Transaction tx;
>
>
>         public void parseLargeXML() throws DocumentException, Exception
>         {
>
>                 SAXReader reader = new SAXReader();
>
>                 try {
>                         session =
> HibernateUtil.getSessionFactory().openSession();
>                 }
>                  catch(Exception e)
>                  {
>                          e.printStackTrace();
>                  }
>
>                 reader.addHandler( "/LoanData/Loan",
>                     new ElementHandler() {
>
>                         public void onStart(ElementPath path) {
>                             // do nothing      count++
>                         }
>
>                         public void onEnd(ElementPath path) {
>
>                               try {
>
>                                Element row = path.getCurrent();
>
>                               Session dom4jSession =
> session.getSession(EntityMode.DOM4J);
>                               tx = session.beginTransaction();
>                                       Document loandoc = row.getDocument();
>
>                              loanList = loandoc.selectNodes("//Loan");
>                              Element e = (Element) loanList.get(0);
>
>                         //parse and add child node Attributes for
> dom4jsession element e
>
>                              e.addAttribute("CurntActivityPeriod","row
> .element("childelement").attributeValue(qname ));
>                              .
>                              .
>                              . upto 100 attributes i am adding
>                         dom4jSession.saveOrUpdate("Loan", e);
>


>                             row.detach();
>                             loanList = null;
>
    //batch insert

>                                           if ((count % 50) ==0)     {
>
>                                 if (tx != null)
>                                 tx.commit();
>                             }
>                         }
>                     }
>                 );
>
>                 Document doc = reader.read(new
> File("c://largeDocument.xml"));
>
>         }
>
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to