Constructing database structure to XML with JDOM

  • Thread starter mikko.tanskanen
  • Start date
M

mikko.tanskanen

Hi,

Is it possible to read the whole database structure to XML file with
JDOM? At the moment I'm getting the structure like this:

List<Classes> classes = session.createQuery("from Classes").list();

Element root = new Element("db");
Document doc = new Document(root);

for ( int i = 0; i < classes().size(); i++ ) {
Element classes = new Element("class");

Long id = new Long(classes().get(i).getId());
classes.setAttribute("id", Integer.toString(id.intValue()) );

Element name = new Element("name");
name.setText(classes().get(i).getName());
classes.addContent(name);

root.addContent(classes);
}

I have very complex database with lots of tables and columns, so it
would be frustrating to write every element name manually. So is there
a possibility that I could get all the element names like "class",
"id", "name" using JDOM? That would help a lot. If you have another way
to do this without using JDOM, I would be happy to hear it.
 
Z

Zaph0d

(e-mail address removed):
Most database allows meta data to be extracted - tables names and
columns included. You could probably use that meta data to
programmatically construct your tree. You might also want to search
"xml publishing", since that's the term for what you're trying to do.

But, (and there is always a "but"), please be aware that xml and
relational data are not the same. While xml _can_ represent the datums,
it usually fails to represent the connections between them if used
naively. Also, while publishing is relatively easy, going the other way
("storage") is much more difficult to be done effectively.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Zaph0d said:
Most database allows meta data to be extracted - tables names and
columns included.

It is even standardized in JDBC.

Connection getMetadata plus getTables and getColumns.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top