title: Parsing and XML with XmlElement and XmlAttributes using JAXB
body: <p>I am unable to unmarshall the below xml using JAXB. Kindly help me to solve this.</p>
  
  <p>My xml looks like this: </p>
  
  <pre><code>   &lt;powerchanges&gt;
       &lt;initialState creationTime="14.08.2012 16:24:01" status="poweredOff" /&gt; 
       &lt;powerchange changeTime="14.08.2012 16:24:49" status="Powered On" /&gt; 
       &lt;powerchange changeTime="27.09.2012 02:17:23" status="Powered Off" /&gt; 
       &lt;powerchange changeTime="27.09.2012 02:51:13" status="Powered On" /&gt; 
       &lt;powerchange changeTime="29.09.2012 05:06:48" status="Powered Off" /&gt; 
       &lt;powerchange changeTime="29.09.2012 07:40:24" status="Powered On" /&gt;   
     &lt;/powerchanges&gt;
  </code></pre>
  
  <p>I am trying to unmarshall the above xml using JAXB.
  Below are my java classes:</p>
  
  <p>PowerChanges.java</p>
  
  <pre><code>@XmlRootElement(name="powerchanges")
  public class PowerChanges {
  @XmlElement(name = "initialState")
  private InitialState initialState;
  
  @XmlElement(name = "powerchange")
  private ArrayList&lt;PowerChange&gt; powerChangeList;
  
  
  public InitialState getInitialState() {
      return initialState;
  }
  public void setInitialState(InitialState initialState) {
      this.initialState = initialState;
  }
  
  public ArrayList&lt;PowerChange&gt; getPowerChangeList() {
      return powerChangeList;
  }
  public void setPowerChangeList(ArrayList&lt;PowerChange&gt; powerChangeList) {
      this.powerChangeList = powerChangeList;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>PowerChange.java:</p>
  
  <pre><code>public class PowerChange {
  
    private String changeTime;
    private String status;
  
    @XmlAttribute
  public String getChangeTime() {
      return changeTime;
  }
  public void setChangeTime(String changeTime) {
  this.changeTime = changeTime;
  }
  @XmlAttribute
  public String getStatus() {
  return status;
  }
  public void setStatus(String status) {
      this.status = status;
  }
  
  } 
  </code></pre>
  
  <p>InitialState.java</p>
  
  <pre><code>public class InitialState {
  
    private String creationTime;
    private String status;
  
    @XmlAttribute
  public String getCreationTime() {
      return creationTime;
  }
  public void setCreationTime(String creationTime) {
      this.creationTime = creationTime;
  }
  @XmlAttribute
  public String getStatus() {
      return status;
  }
  public void setStatus(String status) {
      this.status = status;
  }
  </code></pre>
  
  <p>}</p>