I've got a simple java class that looks something like this:
public class Skin implements Serializable {
public String scoreFontName = "TahomaBold";
...
public int scoreFontHeight = 20;
...
public int blockSize = 16;
...
public int[] nextBlockX = {205, 205, 205, 205};
...
public String backgroundFile = "back.bmp";
...
}
I'd like to read this information from a simple XML file that looks something like this:
"Tahoma Bold"
...
20
...
16
...
<0>2050>
<1>2051>
<2>2052>
<3>2053>
....
"back.bmp"
...
Is there an easy way to inject the information from the xml file directly into the variable names rather than having to parse it manually? I don't mind using an external library.
Any help is appreciated.
解决方案
XStream is really great library for just this.
You can set up aliases for your class and even custom data formats to make the XML file more readable.