It's not a secret anymore!
The moose likes XML and Related Technologies and the fly likes Coverting DB to XML and vice-versa Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Coverting DB to XML and vice-versa" Watch "Coverting DB to XML and vice-versa" New topic

Coverting DB to XML and vice-versa

pankaj bansal

Joined: Mar 07, 2001
Posts: 20
How can I convert my DB(of any DBMS) into XML knowing that multiple interrelated tables are there in my database?
Can I modify XML at run time to insert the data into DB?
I would be very much thankful to get a solution.

Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
DB result set to XML -
You can write a little framework on top of JDBC layer that converts the resultset into an XML document. All column names will become element tags with column values as element content. Since JDBC allows you to retrieve column names from the result set, this shouldn't be too difficult.
XML to DB insert/update/delete
Once you've figured out how want to represent the result set as XML document, this step should be easy, since it is the exact reverse of the previous step. Using a parser, you will extract the element names( which maps to column names ) and elemement content ( which maps to column value ) and build the actual SQL statement.
Remember, XML by itself doesnot have the intelligence to "ask" the database to interpret its content for generating queries. Since XML is pure data, it becomes your onus to provide the middle-tier that looks at the data and take an appropriate action.
Having said that, I encourage you to take a look at various database vendors who are coming up with built-in XML support( the new acronym is XQL !!). Oracle for instance, in their latest version 8i has added extensive XML support. You can create table that has XML columns in it, build relational queries across normal columns and XML columns, retrieve the resultset in an XML format and submit queries as XML documents.
Checkout the XML Home at Oracle Technet website for very interesting articles and free downloads.
We're getting there....
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
pankaj bansal

Joined: Mar 07, 2001
Posts: 20
Thanx Ajith
I got the point. I'll try this.Thanx again.
I agree. Here's the link:
subject: Coverting DB to XML and vice-versa
It's not a secret anymore!