title: Is there a good XML-to-Table that can be used in Java (or PostgreSQL)?
body: <p>I’m looking for something exactly like: XMLTABLE, <a href="http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/" rel="nofollow">http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/</a></p>
  
  <p>Does something like this exist in PostgreSQL, or what would be closest?</p>
  
  <p>Or another way, is there a Java library that can accomplish this?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks to Erwin (the answer in his comment is almost precisely what I was looking for).</p>
  
  <p>However, perhaps I could suggest an extension to this. </p>
  
  <p>Consider, we have an xml document like:</p>
  
  <pre><code>&lt;comments photo_id=“123”&gt;
      &lt;/comment&gt;this is the first comment&lt;/comment&gt;
      &lt;/comment&gt;this is the second comment&lt;/comment&gt;
  &lt;/comments&gt;
  </code></pre>
  
  <p>While, this is a simple example, consider also that <code>“comment”</code> could be quite sophisticated.</p>
  
  <p>My question is now: using the XMLTable function (or Erwin’s implementation), we need to specify a <code>path_to_data</code> i.e. in this case (<code>/comment</code>).</p>
  
  <p>However, if I want my return schema to be something like: <code>[photo_id, comment_text]</code>.</p>
  
  <p>There is no way to get data from the elements of the parent of the datanum.</p>
  
  <p>Is it therefore possible to somehow modify your code to do this?
  My guess is having something more sophisticated than the xpath function, which essentially returns a subset of data by tracing to the parent.</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;comments photo_id=“123”&gt;
      &lt;/comment&gt;this is the first comment&lt;/comment&gt;
  &lt;/comments&gt;
  
  &lt;comments photo_id=“123”&gt;
      &lt;/comment&gt;this is the second comment&lt;/comment&gt;
  &lt;/comments&gt;
  </code></pre>
  
  <p>In this case, we can access <code>“/comments/@photo_id”</code>.</p>