• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DOM or SAX for accessing an XML data structure?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there. I'm looking for some advice, regarding my choice of XML parser.
I am developing a servlet based system for storing details of publications, which registered users can log into and submit details of their papers. Other users can then view these details, through a field search. The publication details are held in an XML file (an XML database, if you will).
I need to decide whether to use the SAX or DOM API to do all of this. I need to be able to search the XML file for various combinations of search fields, edit records already entered, and delete records already entered - so my initial plan was to use the DOM.
However, I cannot guarantee the size of this XML file, as it will be added to by various people and could therefore become larger than the available memory on the server. Is this likely to be a major problem?
Any advice gratefully recieved. Thanks very much.
[ February 02, 2002: Message edited by: Daniel Walker ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me that if there are going to be on-going modifications, you will have to use DOM. If the data gets really large you will probably have to use one of the database programs that stores chunks of XML documents.
Bill
 
Daniel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William
Yeah, I figured as much. The organisation I am doing this for wanted it done with XML, primarily so they didn't have to fork out for a database server, but I am beginning to feel that we are going to run into problems with this approach. It really is crying out for a database backend .
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are FREE databases out there (mysql) that work fairly well. mysql trumpets that they are used by NASA.

If you want to stay with XML, how about using JAXB. It's a data-binding API that has a few 'open' initiatives (Castor, Zeus) and one from sun in early-access release (JAXB API). It seems kinda cool. It allows you to 'marshall' an XML document into java objects. You create new objects or use the setXXXX() methods on existing object to make changes to your XML doc. Then you 'unmarshall' back into an XML document.

The propoenents of JAXB point out that it's less memory used DOM, because a parser does not get loaded into memory, only the data objects. And quicker than SAX.

http://java.sun.com/xml/jaxb/
The book I discovered JAXB in:
http://www.oreilly.com/catalog/javaxml2/
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the ease with which XML can be converted between formats, you could do a quick prototype using DOM or JDOM - if it later grows into a monster you can find other solutions.
Nothing like a quick prototype to let your client discover what they really wanted all along but could not express. Particularly if they are adding and removing fields, XML will be soooo much easier to work with.
I don't think JAXB offers any improvement but I am open to argument.
Bill
 
Daniel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys
Mike, JAXB does look very interesting, but I feel that because I am still dealing with this huge file (for searching through) the memory footprint will be fairly similar - essentially, a lot of the time I have to deal with the whole document at once (if I have got this completely wrong - and it wouldn't be the first time - please set me straight).
William, your comment about the ease with which additional fields can be added to an XML file has raised an important point, which I neglected to mention (or even consider) before: each publication in the XML file can be made up of different fields. It is based on the LaTeX standard (users will be able to upload their LaTeX bibliographies to the servlet for automatic conversion - though I haven't even begun to tackle this yet) so, in actuality, the fact that I am not tied into tables and rows with XML is a blessing.
I think I will use JDOM then. I have been informed it is slightly easier to work with than DOM, though it would be nice to use DOM if possible because of it's recent adoption into the J2SE API. I think I'd better get learning!
Thanks again for the help.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDOM is likely to become a part of the standard Java library - furthermore I understand that it has a mechanism for creating a DOM if necessary.
JDOM should take less memory since it does not create as many objects as DOM for the same input.
It is interesting that so many XML projects are devoted to handling publication data, I also have one on the back burner.
Bill
 
Daniel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having looked at both DOM and JDOM, the ease of use factor has made my decision - JDOM. If it is coming over to the API anyway, great.
My publication project is being undertaken for academics - hence the XML (they do love their open standards, those academics). I agree, it does have a lot of advantages for publication data, and is very promising, but (IMHO) is still a little too unwieldy to be as good as my academics have been led to believe by hype & zeitgeist.
 
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic