Using XML-based object structures to represent data in code/at run-time

Hello,

I have quite a "high level" question which has be bothering me for some time, and I haven't found the subject tackled in any books. I believe J2SE/J2EE is not an important divide here.

Lets say I want to develop a J2SE game application with two programs: a "level designer", and a "level viewer", and I want to store the level files in an XML format.

My question, and I use this example only to try and illustrate it, is:

when coding the level designer or viewer, is it reasonable to use an XML-based object hierarchy for representing a level in code/at run-time, i.e. using the standard Java DOM APIs? Or should one (as I would have done before XML came along) develop a set of classes much closer to modelling the real form of a level, and then add a means to convert those objects to/from to XML format?

This second option of course I would use/would have used if I wasn't thinking about XML, but isn't it sometimes easier to just read in an XML file into a DOM representation and just use the data straight out of that structure, rather than go through the bother of parsing the XML into a set of unrelated objects defined by a different family of classes? What shapes your decision here? And if the second option is best, what is the easiest way of converting to/from the XML?

Thank you for any advice.

Greg

[1384 byte] By [GregScotta] at [2007-11-27 4:54:14]
# 1

Hi Greg,

first I would build a good object model for the game. After modelling the domain objects my next step would be to consider to work with an additional layer with Data Access Objects to be independent of the mapping technology (XML or JDBC, ...) or to use simple JAXB 2.x annotations for my domain objects. I would definitely not use DOM-APIs any more.

Best wishes,

Christian Ullenboom | http://www.tutego.com/

Christian.Ullenbooma at 2007-7-12 10:08:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi Christian,

Can I ask: what about if your domain was quite 'close' to an object/DOM representation of XML?

For instance, what if a game operated by acting out a theatrical script, a spoken conversation, between two characters, perhaps somehow influenced at points by the user, and a particular level was just a different script for the characters.

One could imagine that the object representation of this would in the end be quite similar to how you'd represent XML, i.e. like a tree of nodes, where each node was a line from the script, and some nodes were a decision point where different nodes could be chosen from.

Would you still want to avoid using XML-based classes to represent the underlying 'game', or is there a point where you would 'give it' to the similarity and use existing XML structures directly?

Thank you for any advice

Greg

GregScotta at 2007-7-12 10:08:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...