How to easily load a XML-based Config File into a Java Class? -


I have found a simple Java class that looks like this:

 < Code> Public category skin applied serializable {public string score fontantam = "Tahoma bold"; ... public full scorefotHight = 20; ... public ent blocks block = 16; ... public at [] nextBlockX = {205, 205, 205, 205}; ... public string backgroundfile = "back.bmp"; ...}  



I would like to read this information with a simple XML file that looks like this:

  & lt; Xml & gt; & Lt; Skin & gt; & Lt; ScoreFontName & gt; "Tahoma bold" & lt; / ScoreFontName & gt; ... & lt; Scorefontahight * 20 & lt; / ScoreFontHeight & gt; ... & lt; Block size & gt; 16 & lt; / BlockSize & gt; ... & lt; Next BlockX & gt; & Lt; 0 & gt; 205 & lt; / 0> & Lt; 1 & gt; 205 & lt; / 1 & gt; & Lt; 2 & gt; 205 & lt; / 2> & Lt; 3 & gt; 205 & lt; / 3 & gt; & Lt; NextBlockX & gt; .... & lt; Background File & gt; "Back.bmp" & lt; / BackgroundFile & gt; ... & lt; Skin & gt; & Lt; / XML & gt;  

Is there an easy way to insert information from XML files directly into variable names instead of manually parsing them for injection? I do not feel like using an external library.

Any help is appreciated.

XStream is actually a very great library.

You can set the nickname for your class and even make custom data formats to make the XML file more readable.


Comments