Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] simple xml class

Started by cignox1 Sep 21, 2005 at 2:48 PM 4 replies 1.4k views
Original Post
cignox1
cignox1
In the application I'm writing I have to save some data (both user data and configuration files). They contains both strings and numbers (and date object as well) and I'm not sure how to store them. Should I convert everything into strings? and how do I manage unicode? Then I thought that a partial solution could be using xml. Do you think it could be a good idea? Are you aware of some very simple class to write/read xml files?
Son of Cain
Son of Cain
If you're using XML, you will have to write methods to read data from strings, yes. Not a big deal, though.

I use JDOM, it's simple and very easy to use. However, it builds the entire tree in memory, and in HUGE files that might be an issue. The standard API has a parser as well. Regarding Unicode, the String class has methods do deal with encoding.

Sorry for the rush, if it's still not clear, I'm sure someone here will point you to the right path ;)

Son Of Cain
a.k.a javabeats at yahoo.ca
CaptainJester
CaptainJester
There are 2 APIs included in the JDK to help you parse XML. They take a bit of getting used to, but they aren't that hard. Look at the package "javax.xml.parsers". You can either use DOM or SAX. Start with DOM, it is easier to learn. If you find you are having memory issues, you will have to change to SAX.

The DOM package is:
org.w3c.dom

The SAX packages are:
org.xml.sax
org.xml.sax.ext
org.xml.sax.helpers
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Isolier
Isolier
I don't know if you are interested in writing a library yourself, but it isn't too difficult at all. I wrote one based on the way TinyXml, an Xml lib in Cpp, is structered and found that the development went pretty quickly. There's my two cents...
Tyr
Tyr
I've had experience using both JDOM and Xerces in Java, and for the average wants of saving/loading data I'd recommend JDOM. I've found it to be a nice simple API that'll certainly get the job done; I'm using it extensively in my current game project (a graphic adventure that uses XML for... everything!) and have never had any problems.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.