title: jaxb: bind attribute to element
body: <p>How can I realize this XML with JAXB? Currently the expires attribute in the grantA,C,B elements is not bounded - but it should. I don't know how to associate an element with an attribute. Do I have to create classes for every grantA,C,B?<br>
  XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
      &lt;customers&gt;
          &lt;customer&gt;
              &lt;name&gt;C1&lt;/name&gt;
              &lt;grantA expires=""&gt;false&lt;/grantA&gt;
              &lt;grantB expires=""&gt;true&lt;/grantB&gt;
              &lt;grantC expires=""&gt;true&lt;/grantC&gt;
          &lt;/customer&gt;
          &lt;customer&gt;
              &lt;name&gt;C2&lt;/name&gt;
              &lt;grantA expires=""&gt;false&lt;/grantA&gt;
              &lt;grantB expires=""&gt;true&lt;/grantB&gt;
              &lt;grantC expires=""&gt;true&lt;/grantC&gt;
          &lt;/customer&gt;
          &lt;customer&gt;
              &lt;name&gt;C3&lt;/name&gt;
              &lt;grantA expires=""&gt;false&lt;/grantA&gt;
              &lt;grantB expires=""&gt;true&lt;/grantB&gt;
              &lt;grantC expires=""&gt;false&lt;/grantC&gt;
          &lt;/customer&gt;
      &lt;/customers&gt;
  </code></pre>
  
  <p>XSD:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:element name="name" type="xs:string" /&gt;
  
      &lt;xs:element name="grantA" type="xs:boolean" /&gt;
      &lt;xs:element name="grantB" type="xs:boolean" /&gt;
      &lt;xs:element name="grantC" type="xs:boolean" /&gt;
  
      &lt;xs:element name="customers" type="customers" /&gt;
      &lt;xs:element name="customer"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="name" /&gt;
                  &lt;xs:element name="grantA"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:simpleContent&gt;
                              &lt;xs:extension base="xs:string"&gt;
                                  &lt;xs:attribute name="expires" type="xs:string" /&gt;
                              &lt;/xs:extension&gt;
                          &lt;/xs:simpleContent&gt;
                      &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
                  &lt;xs:element name="grantB"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:simpleContent&gt;
                              &lt;xs:extension base="xs:string"&gt;
                                  &lt;xs:attribute name="expires" type="xs:string" /&gt;
                              &lt;/xs:extension&gt;
                          &lt;/xs:simpleContent&gt;
                      &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
                  &lt;xs:element name="grantC"&gt;
                      &lt;xs:complexType&gt;
                          &lt;xs:simpleContent&gt;
                              &lt;xs:extension base="xs:string"&gt;
                                  &lt;xs:attribute name="expires" type="xs:string" /&gt;
                              &lt;/xs:extension&gt;
                          &lt;/xs:simpleContent&gt;
                      &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:complexType name="customers"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="customer" minOccurs="0" maxOccurs="unbounded" /&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>My current state is:</p>
  
  <p>Customers.java:</p>
  
  <pre><code>@XmlRootElement(name = "customers")
  public class Customers
  {
      private List&lt;Customer&gt;  customerList;
  
      @XmlElement(name = "customer")
      public List&lt;Customer&gt; getCustomerList()
      {
          if (null == customerList)
          {
              customerList = new ArrayList&lt;Customer&gt;();
          }
          return customerList;
      }
  
      public void setCustomerList(List&lt;Customer&gt; customers)
      {
          this.customerList = customers;
      }
  
  }
  </code></pre>
  
  <p>Customer.java</p>
  
  <pre><code>@XmlRootElement(name = "customer")
  @XmlType(propOrder = { "name", "grantA", "grantB", "grantC" })
  public class Customer
  {
      private String  name = "";
      private boolean grantA;
      private boolean grantB;
      private boolean grantC;
  
      @XmlJavaTypeAdapter(CollapsedStringAdapter.class)   
      @XmlElement(name = "name", required=true)
      public String getName()
      {
          return name;
      }
  
      public void setName(String name)
      {
          this.name = name;
      }
  
      @XmlElement(name = "grantA", required=true)
      public boolean isGrantA()
      {
          return grantA;
      }
  
      public void setGrantA(boolean grantA)
      {
          this.grantA = grantA;
      }
  
  
  
      @XmlElement(name = "grantB", required=true)
      public boolean isGrantB()
      {
          return grantB;
      }
  
      public void setGrantB(boolean grantB)
      {
          this.grantB = grantB;
      }
  
      @XmlElement(name = "grantC", required=true)
      public boolean isGrantC()
      {
          return grantC;
      }
  
      public void setGrantC(boolean grantC)
      {
          this.grantC = grantC;
      }
  
  
      @Override
      public String toString()
      {
          return "" + name + "[ " + grantA + ", " + grantB + " " + grantC + " ]";
      }
  
  }
  </code></pre>