JDOM keeping the document valid during insertions...

  • Thread starter Marcio DeBarros
  • Start date
M

Marcio DeBarros

Hi,

This is my first time with XML, and I am using JDOM, on a Java
client/server application, where the server will store data in XML files
(not using any DBMS). I came across the following problem.

My server class will have a method to receive an XML document, let's say
user.xml, detach its root element and attach to an XML document build in
the server called usersfile.xml. I am using a SAXBuilder to validate
both documents when they are loaded. However I tough of a situation,
where if some unforeseen reason, the new document arrives with an id
(unique), which already exists on the server file, that new document
will be added to the tree, eventually saved/flushed to disk.

But I realized that since master/repository document is already loaded,
the duplicate id, will not become evident until I have to reload the
master document again, which it may be much later, and too late because
the duplicate Id is already in.

So what I am wondering, is how will I be able to ensure that the new
document will not make the master document invalid before it actually
gets inserted on the tree ?

I obviously thought about doing a search in the tree for the Id, and
only proceed with the insertion not found, but that seems to me a bit
hectic... Which raises another question: I've been doing a search in the
tree by getting the children back as a list, and iterating through the
list (Is this the proper way to do so ?). Maybe this is the way to go,
and I am expecting too much of JDOM without using a DBMS ?

Thanks in advance for any help...

--MD.
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top