title: JAVA: Build XML document using XPath expressions
body: <p>I know this isn't really what XPath is for but if I have a HashMap of XPath expressions to values how would I go about building an XML document. I've found dom-4j's 
  DocumentHelper.makeElement(branch, xpath) except it is incapable of creating attributes or indexing. Surely a library exists that can do this?</p>
  
  <pre><code>Map xMap = new HashMap();
  
  xMap.put("root/entity/@att", "fooattrib");
  xMap.put("root/array[0]/ele/@att", "barattrib");
  xMap.put("root/array[0]/ele", "barelement");
  xMap.put("root/array[1]/ele", "zoobelement");
  </code></pre>
  
  <p>would result in:</p>
  
  <pre><code>&lt;root&gt;
  &lt;entity att="fooattrib"/&gt;
  &lt;array&gt;&lt;ele att="barattrib"&gt;barelement&lt;/ele&gt;&lt;/array&gt;
  &lt;array&gt;&lt;ele&gt;zoobelement&lt;/ele&gt;&lt;/array&gt;
  &lt;/root&gt;
  </code></pre>