xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Pickering <mp_s...@yahoo.com>
Subject Using XML to create Java objects
Date Wed, 30 Oct 2002 05:37:19 GMT
Hello all,

I use XML on a daily basis in my day job and recently
I've started work on some gaming projects that use XML
to store configuration and game data.  One of the most
tedious tasks I've had to deal with in both realms is
the parsing of XML in order to create Java objects,
both simple and complex.

I know libraries and tools exist to do this, but they
all have one major drawback: they require me to write
code to describe the objects I want to create and map
the XML to them.

I've written an engine that allows me to express
simple and composite Java objects as XML and have Java
objects come out without any work on my part other
than providing a listener to capture the objects as
they are created.

The engine uses Java Reflection to construct objects
and call methods.  Methods can accept simple
parameters or other objects, which can also be
expressed as nested XML.

The XML markup has to follow a few simple rules and a
mechanism is provided to allow the user to define
constants that can substitute one value for another as
well as define the tags that map to various objects.  

Here is a simple example of some XML markup that
creates a Java Properties object:

        <twgp:mapping parentTag="*" tag="myprops"
        <property key="prop1" value="value1"/>
        <property key="prop2" value="value2"/>
        <!-- Since Properties is a subclass of
Hashtable, the following shows
        we can also call put() instead of
setProperty(). -->
        <put key="prop3" value="value3"/>

I've been using this engine to built game
configuration files as well as to build config files
for some rules-based code I use in my day job.  

My question to the list is this: Would there be any
interest to the community at large in such an engine?

I was planning to release the engine along with the
gaming code, but it is being maintained as a separate
codebase.  I am willing to break the engine out and
maintain it as a separate project if there is
sufficient interest.

The engine is general purpose but is scoped for
applications that use XML as configuration data but
don't want the hassle of having to parse the XML to
suit differing requirements.  It is not a
serialization mechanism (although I plan to add a
converter to take instantiated objects and dump out
compatible XML markup).  It certainly isn't a "be-all,
end-all" solution to the problem of XML-Java
conversion, but can address a decent amount of the
problems that an average developer may face in using
XML and Java.

If anyone would like to know more, please reply to the
list or me directly.  If this ins't the appropriate
forum for this, I do apologize and I will repost this
to the Jakarta list and take my chances there.

Matt Pickering

Do you Yahoo!?
HotJobs - Search new jobs daily now

In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org

View raw message