title: XML to Java POJO
body: <p>I'm not an specialist on XML and much less in Java (Pretty Noob actually). I have the following XML:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;airports&gt;
      &lt;airport iata=&quot;AAC&quot; airportName=&quot;El Arish International Airport&quot; countryCode=&quot;EG&quot;/&gt;
      &lt;airport iata=&quot;AAE&quot; airportName=&quot;Annaba&quot; countryCode=&quot;DZ&quot;/&gt;
      &lt;airport iata=&quot;AAF&quot; airportName=&quot;Apalachicola&quot; countryCode=&quot;US&quot; regionCode=&quot;FL&quot;/&gt;
      &lt;airport iata=&quot;AAG&quot; airportName=&quot;Avelino Vieira Airport&quot; countryCode=&quot;BR&quot;/&gt;
      &lt;airport iata=&quot;AAH&quot; airportName=&quot;Aachen&quot; countryCode=&quot;DE&quot;/&gt;
      &lt;airport iata=&quot;AAL&quot; airportName=&quot;Aalborg&quot; countryCode=&quot;DK&quot;/&gt;
      &lt;airport iata=&quot;AAN&quot; airportName=&quot;Al Ain&quot; countryCode=&quot;AE&quot;/&gt;
  &lt;/airports&gt;
  </code></pre>
  <p>Then i created this</p>
  <pre><code>import java.util.Collection;
  import jakarta.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class JAXBAirports {
      Collection&lt;JAXBAirport&gt; airports;
  
  public Collection&lt;JAXBAirport&gt; getAirports() {
      return airports;
  }
  
  public void setAirports(Collection&lt;JAXBAirport&gt; airports) {
      this.airports = airports;
  }
  </code></pre>
  <p>}</p>
  <p>and this other Java Class</p>
  <pre><code>@XmlRootElement(name = &quot;airport&quot;)
  @XmlAccessorType(XmlAccessType.FIELD)
  public class JAXBAirport {
  
      private String iata;
      private String airportName;
      private String countryCode;
  
  public String getIata() {
      return iata;
  }
  public void setIata(String iata) {
      this.iata = iata;
  }
  
  public String getAirportName() {
      return airportName;
  }
  public void setAirportName(String airportName) {
      this.airportName = airportName;
  }
  public String getCountryCode() {
      return countryCode;
  }
  public void setCountryCode(String countryCode) {
      this.countryCode = countryCode;
  }
  </code></pre>
  <p>}</p>
  <p>Then it should be as simple to do this</p>
  <pre><code>JAXBContext context = JAXBContext.newInstance(JAXBAirports.class);
  Unmarshaller marshal = context.createUnmarshaller();    
  JAXBAirports air = (JAXBAirports) marshal.unmarshal(MyInputStream);`
  </code></pre>
  <p>Nevertheless i keep getting a</p>
  <p>jakarta.xml.bind.UnmarshalException: Unexpected element...I noticed about annotations but when i use them it says that are ilegal.. Im pretty sure its something really dump on my side but has wasted several hours...</p>
  <p>Can someone give me the straight forward answer ?... Thanks in advance..</p>