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.
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.