Best approach to load XML data and transform it into spatials?

So, I have a question, again. I’m developing a trading card game and I’m thinking about the best way to set up the cards in the actual game. I guess the best way to save the decks for the player and the AI is in an XML format that simply contains a list of all the cards in that respective deck.

I would read that XML file once at the beginning of the game, shuffle it and then save it in an ArrayList or Stack-like structure (by using custom objects as a representation of cards, of course). When a player plays one of those cards, they would become spatials and I would attach data to these spatials according to the card’s attributes (like hitpoints, attack damage, defense, and so on).

The most obvious approach to do this would be to use a standard DOM parser, but I guess there are faster ways that suit the requirements of a game better. Also, I’d like to know if there are some built-in functions in jME that I could use. I’ve got to admit that I’m not very familiar with XML in general and therefore don’t know what’s best suited and how to use it exactly, so a little help concerning that would be very precious to me :slight_smile:

(I already searched the forum for similar questions, of course, but I guess I need some additional help - I guess I’m just too inexperienced…)

To best approach is to not use XML seeing as you don’t know it that well. Use JSON or just write your own file parser.

For standard Java, without 3’d part libraries, it offers at least three approaches to readin XML. DOM-based, or SAX/StAX: this offers a simple example - http://blog.sanaulla.info/2013/05/23/parsing-xml-using-dom-sax-and-stax-parser-in-java/

Then there’s the heavy hitter JAXB, https://jaxb.java.net/tutorial/

I second the JSON suggestion. It’s a simple format and readily supported in pretty much every language.

Using JSON sounds legit. I’ll try that, thank you. By the way, do you have any suggestions on where to save the respective files containing the deck information, regarding the eventual deployment? Of course I don’t want anyone to be able to read and edit those files, should I just create a new asset folder?

Yeah, just make an asset folder.

Thanks, guys. It’s awesome how quickly one can get help here.