Advertisement

02.04.2008 at 04:57PM PST, ID: 23136890 | Points: 500
[x]
Attachment Details

Issue with XML transormation to DB using Hibernate

Asked by srinivasysr2003 in Extensible Markup Language (XML), Java Programming Language, J2EE Frameworks

Tags:

Hi All,

I have requirement to transform a XMLfile to Database. My design should be such that, in future xml strucure changes, I would not want to change any code or write new code, but with a configuration change this should work

I am using Hibernate for acheiving this.

I am not creating any POJO's for this xml structure. I just want to defined some rules in config and based on that want to import xml information to a Database

I am attaching sample xml file, hynernate config file and Java class I have written to do this.

My problem is that I am able to extract only information which is stored as attributes. I am not getting values from the sub elements.

In the attached XML i am extracting category information into a Database. I want to get the "title" of each category which is under "details" tag. I am able to get all other fields into the table,  execpt title.

Can any one throw some pointers on this. Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
package test;
import java.io.File;
import java.util.Iterator;
import java.util.List;
 
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.hibernate.EntityMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
 
 
 
public class ImportXMLToDB {
 
	/**
	 * @param args
	 */
	public static void main(String[] args)throws Exception {
		Configuration config=new Configuration();
		config.addFile("C://ecllipse//workspace//Hybernate//conf//portal.hbm.xml");
		//config.addFile("C://ecllipse//workspace//Hybernate//conf//hibernate.properties");
		SessionFactory sessionFactory=config.buildSessionFactory();
 
		Session sess =sessionFactory.openSession();
		org.hibernate.Transaction tx = sess.beginTransaction();
 
 
		Session dom4jSession = sess.getSession(EntityMode.DOM4J);
		SAXReader saxReader = new SAXReader();
		Document document = saxReader.read(new File("C://ecllipse//workspace//Hybernate//input//portal.xml"));
		List list = document.selectNodes("//taxonomy/*");
		
		
		Iterator iter = list.iterator();
		
 
 
		while (iter.hasNext()) {
			   Object obj = iter.next();
			  // org.dom4j.tree.DefaultElement element = (org.dom4j.tree.DefaultElement) catalog;
			  
			   dom4jSession.saveOrUpdate("category", obj);
			
			}
		sess.flush();
		 tx.commit();
		 sess.close();
 
 
 
 
	}
 
}
Attachments:
 
hibernate configurtation file
 
 
 
[+][-]02.05.2008 at 08:08AM PST, ID: 20824089

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.05.2008 at 04:24PM PST, ID: 20828509

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 02:55PM PST, ID: 20836616

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.07.2008 at 11:28AM PST, ID: 20844138

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.26.2008 at 10:52AM PST, ID: 20987382

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.15.2008 at 12:16AM PDT, ID: 21131727

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628