title: With MOXy and XPath, is it possible to unmarshal a list of attributes?
body: <p>Edit: here's how I'm loading the XML document, as I used it in Blaise's answer.  I'm loading it like this because I want to work with a node, not the whole doc.  Even using the whole document I'm still having trouble when loading in this manner.</p>
  
  
  
  <pre><code>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setValidating(false);
  factory.setNamespaceAware(false);
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document doc = builder.parse("[path to doc]/input.xml");
  TestClass testClass = (TestClass) unmarshaller.unmarshal(doc);
  </code></pre>
  
  <p>I've got XML that looks like this:</p>
  
  
  
  <pre><code>&lt;test&gt;
    &lt;items&gt;
      &lt;item type="cookie"&gt;cookie&lt;/item&gt;
      &lt;item type="crackers"&gt;crackers&lt;/item&gt;
    &lt;/items&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p>And a class:</p>
  
  
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlRootElement(name = "test")
  public class TestClass
  {
    @XmlPath("items/item/text()")
    @XmlElement
    private ArrayList&lt;String&gt; itemList = new ArrayList&lt;String&gt;();
  
    // getters, setters omitted
  }
  </code></pre>
  
  <p>The above code will work whether or not I have <code>@XmlElement</code>, and I get an ArrayList containing [cookie, crackers].</p>
  
  <p>If I change the declaration above to </p>
  
  <pre class="lang-java prettyprint-override"><code>@XmlPath("items/item/@type")
  @XmlElement
  private ArrayList&lt;String&gt; itemList = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>my ArrayList is empty.  </p>
  
  <p>My ultimate goal is to just have attributes so my XML would look like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;test&gt;
    &lt;items&gt;
      &lt;item type="cookie"/&gt;
      &lt;item type="crackers"/&gt;
    &lt;/items&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p>Is what I'm trying to do, pull out a list of attributes using XPath, possible, and if so, how?</p>
  
  <p>Thank you.</p>