You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Alec Swan <au...@yahoo.com> on 2006/03/14 00:40:39 UTC

XML representation of relational data

Hello,

I am working on a project where I need to pre-populate the database with some data defined in an XML file. We have finalized the database schema, but I am still not sure what is the best way to map our XML schema to it.

I have the following requirements:
1) define elements AND relationships between them using XML schema
2) generate Java classes from the schema
3) validate and unmarshal an XML instance in a Java object graph
4) navigate through the object graph (up AND down)
5) be able to easily locate a Java object given its id, which is entered as an attribute of an XML element (this may not be required if I can get two generated java objects to reference the same java object)

I started using JAXB and was able to get the second and the third requirements satisifed. I got stuck on the last two and decided to re-evaluate my decision to use JAXB.

Let's assume that I have the following tables in my relational database: 
Machine (ip, userId)
User (userId, name) 
Group (name, userId)

I would like to create an XML file, which defines users, machines and groups. I also want to be able to define the relationship between machines and users and between groups and users. 

Suppose, I have one user, one machine and one group associated with the user. I don't want to define the user element within <machine> and also within <group>, because in this case there is no way to indicate that the same user is being referenced. I would rather define the <user> first and then have <machine> and <group> SOMEHOW reference it. I could give <user> an id and then use this id to refer to this user element from within <machine> and <group>. However, in this case I would like the generated Java objects corresponding to <group> and <machine> to reference the SAME user object.

I would love to hear your ideas on how to map XML data to relational schema and satisfy my five requirements. I hope that Xalan will be able to help me out with this.

Thanks.

Alec

		
---------------------------------
Yahoo! Mail
Bring photos to life! New PhotoMail  makes sharing a breeze.