title: Performance: DOM-XPath versus Key Value lookup
body: <p>I'm seeking some design advice relating to avoiding a potential performance issue.</p>
  
  <p>Short version: Generally speaking, how much slower is querying a DOM using XPath than querying two hashmaps?</p>
  
  <p>Longer and mpre specific version:</p>
  
  <p>I'm creating a Java application which has to read an XML file as part of its start-up. The file will probably have a maximum of 8200 attributes configured as shown in the below XML. Theoretically there would be a maximum 100 mapping Elements each with 2 attributes. Each element containing 1 to 40 elements with pairs of attributes. So a total of (40 * 2) * 100 + 200 text attributes.</p>
  
  <pre><code>&lt;mapping source="A" target="B"&gt;
      &lt;field fname="" tname=""/&gt;
      &lt;field fname="" tname=""/&gt;  
      &lt;field fname="" tname=""/&gt;  
      &lt;field fname="" tname=""/&gt;
  &lt;/mapping&gt;
  </code></pre>
  
  <p>It crossed my mind to extract the info into 2 hashmaps which will then be used to do lookups during the execution of the program. I'm only interested in finding the mapping "source" from which I will lookup both the corresponding "target" and then use any child "fname" to look up the corresponding "tname". </p>
  
  <p>I'm just wondering how much slower it would be to use XPath and query the DOM each time I want some information compared with creating a hashmap of (e.g.) a "mappings class" which itself contains a hashmap of fname/tname kv pairs... </p>
  
  <p>Thanks in advance for any tips and hope this makes sense.</p>
  
  <p>Kevin</p>