title: Loading settings from XML file into a Java class
body: <p>I have an XML file containing a bunch of simulation settings (partial example below). I would like to load these settings into a Java class, so that the settings are available later without having to write cumbersome DOM/XPath jargon (and import the associated packages) every time I (or another programmer who isn't fluent in DOM/XPath) want to access a specific setting. </p>
  
  <p>Right now I set up a number of sub-classes that represent each level of information in the XML tree, and "manually" parse out the info to all these sub-classes. The result is, for example, that if I want to get Direction number 3, I can write:</p>
  
  <pre><code>settings.setup.directions[3]
  </code></pre>
  
  <p>I guess this works ok, but it sure feels rigid. </p>
  
  <p>Is there a smarter way of doing this? Should we just stick to the DOM and skip this conversion business? (Please no!)</p>
  
  <p>Note that I am not looking for instructions on how to load an XML file -- I know how to load it into a DOM document and parse it with XPath. </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Settings&gt;
      &lt;Identity&gt;
          &lt;JobNumber&gt;1234567&lt;/JobNumber&gt;
          &lt;SimulationName&gt;MyTest&lt;/SimulationName&gt;
      &lt;/Identity&gt;
      &lt;PreProcessing &gt;
          &lt;Tolerance&gt;0.01&lt;/Tolerance&gt;
      &lt;/PreProcessing &gt;
      &lt;PreprocessedInputData&gt;
          &lt;PreChewedThing&gt;&lt;/PreChewedThing&gt;
          &lt;OtherThing&gt;&lt;/OtherThing&gt;
      &lt;/PreprocessedInputData&gt;
      &lt;Setup&gt;
          &lt;DomainExtent&gt;
              &lt;XMin&gt;260&lt;/XMin&gt;
              &lt;XMax&gt;290&lt;/XMax&gt;
              &lt;YMin&gt;523&lt;/YMin&gt;
              &lt;YMax&gt;565&lt;/YMax&gt;
          &lt;/DomainExtent&gt;
          &lt;Directions&gt;
              &lt;Direction Index = "1"&gt;0&lt;/Direction&gt;
              &lt;Direction Index = "2"&gt;10&lt;/Direction&gt;
              &lt;Direction Index = "3"&gt;20&lt;/Direction&gt;
              &lt;Direction Index = "4"&gt;30&lt;/Direction&gt;
          &lt;/Directions&gt;
      &lt;/Setup&gt;
  &lt;/Settings&gt;
  </code></pre>