Storing XML Files in Database

1.7k Views Asked by At

I have to create a desktop application in Java 6. Program should be able to communicate with other system using XML files (sending/receiving). Every single XML file is connected with its XSD, tags describing its content, username and status of the document. Application should provide such functionality as searching, modyfying etc. XML content.

The question is: how should I store all these information retaining logical connections?

I came up with an idea to store it using XML database - BaseX. In other words, storing XML files with information connected to them in one big XML (database) file.

Sample database:

<?XML VERSION="1.0"?>
<mySampleRecord id="1">
<XMLcontent> // Content of XML file (...) </XMLcontent>
<XMLschema> // Content of XSD file (...) </XMLschema>
<tags>j2ee java xml</tags>
<username>File Owner</username>
<status>received</status>
</mySampleRecord>
<mySampleRecord id="2">
<XMLcontent> // Content of XML file (...) </XMLcontent>
<XMLschema> // Content of XSD file (...) </XMLschema>
<tags>doc xls mdb</tags>
<username>Admin</username>
<status>sent</status>
</mySampleRecord>

I was also wondering if it's possible BaseX to read <XMLContent> node and then treat its content as XML enabling me to perform XQuery operations.

Hope its understandable ;)

Thanks for any hints and suggestions.

2

There are 2 best solutions below

0
On

Didn't quite get it. :)

So you want to store several XMLFiles with the corresponding schema in another XML file?

Why do that? Just treat each XML file individually. Have them as .xml files inside your .jar .. thus each client can get access to it.

cheers

2
On

If I understood you correctly you should create table SAMPLE_RECORD with fields id (PK) user_name status

then create table TAG with fields record_id (FK to table record) tag

Create class SampleRecord Now write code that parse XML and create instances of SampleRecord. Then implement logic that stores collection of SampleRecord in DB and reads it from there. You can either use ORM or just old good plain JDBC.

That's it.