[jdom-interest] Should I convert to/from org.jdom.Document
arosen at silverstream.com
Mon Jan 21 09:10:06 PST 2002
Usually you want to deal with application-specific classes for the important
concepts in your system. If you're just reading and writing a few
preferences from an XML file, then directly manipulating the XML is probably
fine. For more important or more frequently used objects, I'd build a
front-end for the JDOM objects.
You can do this in 3 different ways:
1) Your objects convert to and from XML only when necessary (e.g. on save
2) Your objects point to JDOM objects, and store their data there.
3) Your objects *are* JDOM objects (subclasses), and store their data there.
I usually recommend avoiding option #3, it leads to more hassles than it's
worth. I don't usually like option #1, because you have to remember to keep
your own representation, and the conversion logic, in sync. I like option
#2, with code along these lines:
public class Car
public String getManufacturer()
public void setManufacturer(String s)
private Element m_xml;
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On
Behalf Of Naresh Bhatia
Sent: Friday, January 18, 2002 4:17 PM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] Should I convert to/from org.jdom.Document
I have a quick design question for the group. When using an XML parser such
as JDOM, is it better for the application to work directly with the document
tree (such as org.jdom.Document) or should it use an application specific
model and convert to/from the document tree? What are the pros/cons of the
two approaches, where does one make sense over the other?
More information about the jdom-interest