title: JAXB marshaling and unmarshalling multiple XML elements into a single class and reverse
body: <p>I'm trying to marshal and unmarshal the following "attrName" and "attrType" XML-Elements into a single class. (At the moment I read the values individually and construct my objects after the unmarshalling in Java.)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;wrapper&gt;
      &lt;someOtherElement&gt;xxx&lt;/someOtherElement&gt;
      &lt;attrName ref="a"&gt;xxx&lt;/attrName&gt;
      &lt;attrName ref="b"&gt;xxx&lt;/attrName&gt;
      &lt;attrName ref="c"&gt;xxx&lt;/attrName&gt;
      &lt;attrType attrRef="a"&gt;xxx&lt;/attrType&gt;
      &lt;attrType attrRef="b"&gt;xxx&lt;/attrType&gt;
      &lt;someOtherElement&gt;xxx&lt;/someOtherElement&gt;
  &lt;/wrapper&gt;
  </code></pre>
  
  <p>The "ref" XML-Attribute is used to identify a attribute and as a reference for the "attrType" XML-Element. But the "attrType" XML-Element is optional and must not be there. There can not be a "attrType" XML-Element without a "attrName" XML-Element.</p>
  
  <p>I need to generate a List of "attribute" objects of the class:</p>
  
  <pre class="lang-java prettyprint-override"><code>package example;
  
  public class Attribute {
  
      private String name;
  
      private String ref;
  
      private String type;
  
      public String  getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name= name;
      }
  
      public String  getRef() {
          return ref;
      }
  
      public void setRef(String ref) {
          this.ref= ref;
      }
  
      public String  getType() {
          return type;
      }
  
      public void setType(String type) {
          this.type= type;
      }
  }
  </code></pre>
  
  <p>I already found following relating <a href="https://stackoverflow.com/questions/5325362/jaxb-unmarshalling-multiple-xml-elements-into-single-class">question</a>. But It didn't help me in finding a solution for my problem.
  The problem is to find all related attribute names and types to construct a Java object.</p>
  
  <p>I'd be grateful for any tips or advice in the right direction. If I did not explained anything satisfactory, please don't hesitate to ask as English is not my native tongue.</p>
  
  <blockquote>
    <p>PS: I know I could use a different XML structure and solve the problem easily. But that is not possible for me.</p>
  </blockquote>