Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I was wondering how you would go about writing and the reading from an XML file using the Java library Slick2D.

I have googled for the last couple of days and have found nothing succinct and simple that explains what I'm looking for.

I am looking for 3 things:-

  1. How to create an XML file (would be awesome to be able to search a directory to see if there is an existing file and only create a new file if one does not already exist.
  2. How to write to the created XML file.
  3. How to read from the found XML file.

The reason for this is that I'm trying to create a save/load class for a game.

Just a general snippet of code, that I'd be able to modify for my needs would be great even for a learning experience.

So now for my question, does anyone have any information that may help me on my quest to succeed in my above stated three goals?

share|improve this question

closed as off topic by Byte56, Patrick Hughes, Anko, Josh Petrie, bummzack Apr 20 '13 at 10:18

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
As far as I can see, this is unrelated to Slick2D or lwjgl. You seem to be asking "how to handle XML files in Java", which is a pretty easy question to Google. –  Liosan Apr 19 '13 at 13:19
    
A easy to Google question that displays no easy answer, that's why I asked this question, because I wanted an easy to understand yet succinct way of understanding the subject. It is related to Slick2D and LWJGL in the sense that they are the library's that I am using. –  GeorgeV Apr 19 '13 at 13:26
3  
You're asking how to do X with tools that were made to do Y. Use different tools. Search for Java libraries made for reading and writing XML. KXmlParser is a decent one. Your first question is about file IO and the other two should be covered in the documentation for whatever XML library you decide to use. –  Byte56 Apr 19 '13 at 15:27

1 Answer 1

up vote 1 down vote accepted

Check out XStream, I found it to be extremely easy to use for serializing/de-serializing Java Objects.

For working with files such as checking if they exist, use the Java API: java.io.File is a simple way to check such a thing.

I think you should familiarize yourself with basic Java input/output before chasing goals such as serialization with XML.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.