Java XML processing newbie question
I have written a JSP webapp that represents a horse stud book.
I have used XML as a way to store data. When my webapp loads it loads the entire XML file into an java.util.ArrayList of javaBeans that represent the horse pedigrees. I then manipulate the ArrayList and search through it instead of parsing the XML file itself each time I want to search etc. Now I know this is very bad programming practice as it is very memory inefficient. I need to correct the code to be more efficient before the files that my client uses get too large to handle. Would using JDOM be the right way togo? If anyone has any better ideas I would greatly appreciate the help.
Converting the code to use a relational database is out of the question as my client doesnt have a database administrator and the hardware they use is preaty outdated.
Thanks in advance.
popsavin@yahoo.com
[893 byte] By [
bitbybita] at [2007-11-27 6:33:17]

Why is this practice very memory inefficient?
ArrayList is a list implementation with a relatively small memory footprint. Obviously I cannot make any (intelligent) assumption about your javaBeans, but unless you store lots of unneccessary data these are probably ok, too.
Using JDOM (or the w3c DOM stuff) means that the entire XML content is stored in memory, too, so you actually cannot improve memory usage by using a DOM implementation.
If you need to reduce your memory usage because of large datasets, your only option will be not to keep all the data in memory, but to load it on demand. This always comes with a performance penalty, even more so when using XML which is IMHO unsuited for any load on demand approach (since you have to parse the entire file).
> Converting the code to use a relational database is
> out of the question as my client doesnt have a
> database administrator and the hardware they use is preaty outdated.
There are lightweight databases which can even be embedded into running programs. See http://hsqldb.org/ for exmaple.
You have made a valid point about DOM based structures they would have to keep XML tags in memory as well as data. However I was not aware that the entire XML file was loaded into the operating memory.
The XML file that I have created should have about 3000 records when info is populated and each record has about 15 strings of information
Do you see any problem with keeping all 3000 javabeans in an ArrayList in the memory while for the duration of the web application?
I know the question is dumb but this is my first app that will be used comercialy.
As I have said a relational database is not an option mainly beacose the end user would not know how to maintain it. (Backup and restore data)
Thanks.