title: Exception in thread "main" "javax.xml.bind.UnmarshalException: unexpected element" BUT it is required to allow both test-classes and test-class
body: <p>I am getting an Exception while running the following code :</p>
  
  <pre><code>JAXBContext context = JAXBContext.newInstance(TestClassesType.class , TestClassType.class);
  Unmarshaller um = context.createUnmarshaller();
  System.out.println("XMLFILE ==  " + xmlFilePath);
  JAXBElement tcstJaxb = (JAXBElement) um.unmarshal(new FileReader(xmlFilePath));
  </code></pre>
  
  <p>Exception : </p>
  
  <pre><code>Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"test-class"). Expected elements are &lt;{}test-classes&gt;
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:243)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:238)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105)
  </code></pre>
  
  <p>I have speified both TestClassesType.class , TestClassType.class in code segment : <code>JAXBContext context = JAXBContext.newInstance(TestClassesType.class , TestClassType.class);</code> But still When some xml starts with test-classes it is able to unmarshall it but classes that starts with test-class , it is unable to unmarshall it and throws the above Exception.
  Classes used :
  TestClassesType</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "test-classesType", propOrder = {
      "testClass"
  })
  public class TestClassesType {
  
      @XmlElement(name = "test-class")
      protected List&lt;TestClassType&gt; testClass;
  
      /**
       * Gets the value of the testClass property.
       * 
       * &lt;p&gt;
       * This accessor method returns a reference to the live list,
       * not a snapshot. Therefore any modification you make to the
       * returned list will be present inside the JAXB object.
       * This is why there is not a &lt;CODE&gt;set&lt;/CODE&gt; method for the testClass property.
       * 
       * &lt;p&gt;
       * For example, to add a new item, do as follows:
       * &lt;pre&gt;
       *    getTestClass().add(newItem);
       * &lt;/pre&gt;
       * 
       * 
       * &lt;p&gt;
       * Objects of the following type(s) are allowed in the list
       * {@link TestClassType }
       * 
       * 
       */
      public List&lt;TestClassType&gt; getTestClass() {
          if (testClass == null) {
              testClass = new ArrayList&lt;TestClassType&gt;();
          }
          return this.testClass;
      }
  
  }
  </code></pre>
  
  <p>TestClassType :</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "test-classType", propOrder = {
      "content"
  })
  public class TestClassType {
  
      @XmlElementRef(name = "test-method", type = JAXBElement.class, required = false)
      @XmlMixed
      protected List&lt;Serializable&gt; content;
      @XmlAttribute(name = "name")
      protected String name;
  
      /**
       * Gets the value of the content property.
       * 
       * &lt;p&gt;
       * This accessor method returns a reference to the live list,
       * not a snapshot. Therefore any modification you make to the
       * returned list will be present inside the JAXB object.
       * This is why there is not a &lt;CODE&gt;set&lt;/CODE&gt; method for the content property.
       * 
       * &lt;p&gt;
       * For example, to add a new item, do as follows:
       * &lt;pre&gt;
       *    getContent().add(newItem);
       * &lt;/pre&gt;
       * 
       * 
       * &lt;p&gt;
       * Objects of the following type(s) are allowed in the list
       * {@link String }
       * {@link JAXBElement }{@code &lt;}{@link TestMethodType }{@code &gt;}
       * 
       * 
       */
      public List&lt;Serializable&gt; getContent() {
          if (content == null) {
              content = new ArrayList&lt;Serializable&gt;();
          }
          return this.content;
      }
  
      /**
       * Gets the value of the name property.
       * 
       * @return
       *     possible object is
       *     {@link String }
       *     
       */
      public String getName() {
          return name;
      }
  
      /**
       * Sets the value of the name property.
       * 
       * @param value
       *     allowed object is
       *     {@link String }
       *     
       */
      public void setName(String value) {
          this.name = value;
      }
  
  }
  </code></pre>
  
  <p>I have a few xmls that start with test-classes and some that starts with test-class tag. I want to allow both of these. Is there any way to accomplish this?</p>
  
  <p>The ObjectFactory class so generated is the one below : </p>
  
  <pre><code>@XmlRegistry
  public class ObjectFactory {
  
      private final static QName _TestClasses_QNAME = new QName("", "test-classes");
      private final static QName _TestClassTypeTestMethod_QNAME = new QName("", "test-method");
  
      /**
       * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.jaxb.scenario
       * 
       */
      public ObjectFactory() {
      }
  
      /**
       * Create an instance of {@link TestClassesType }
       * 
       */
      public TestClassesType createTestClassesType() {
          return new TestClassesType();
      }
  
      /**
       * Create an instance of {@link ParamsType }
       * 
       */
      public ParamsType createParamsType() {
          return new ParamsType();
      }
  
      /**
       * Create an instance of {@link TestCaseType }
       * 
       */
      public TestCaseType createTestCaseType() {
          return new TestCaseType();
      }
  
      /**
       * Create an instance of {@link TestClassType }
       * 
       */
      public TestClassType createTestClassType() {
          return new TestClassType();
      }
  
      /**
       * Create an instance of {@link AssertType }
       * 
       */
      public AssertType createAssertType() {
          return new AssertType();
      }
  
      /**
       * Create an instance of {@link TestMethodType }
       * 
       */
      public TestMethodType createTestMethodType() {
          return new TestMethodType();
      }
  
      /**
       * Create an instance of {@link AssertsType }
       * 
       */
      public AssertsType createAssertsType() {
          return new AssertsType();
      }
  
      /**
       * Create an instance of {@link ParamType }
       * 
       */
      public ParamType createParamType() {
          return new ParamType();
      }
  
      /**
       * Create an instance of {@link JAXBElement }{@code &lt;}{@link TestClassesType }{@code &gt;}}
       * 
       */
      @XmlElementDecl(namespace = "", name = "test-classes")
      public JAXBElement&lt;TestClassesType&gt; createTestClasses(TestClassesType value) {
          return new JAXBElement&lt;TestClassesType&gt;(_TestClasses_QNAME, TestClassesType.class, null, value);
      }
  
      /**
       * Create an instance of {@link JAXBElement }{@code &lt;}{@link TestMethodType }{@code &gt;}}
       * 
       */
      @XmlElementDecl(namespace = "", name = "test-method", scope = TestClassType.class)
      public JAXBElement&lt;TestMethodType&gt; createTestClassTypeTestMethod(TestMethodType value) {
          return new JAXBElement&lt;TestMethodType&gt;(_TestClassTypeTestMethod_QNAME, TestMethodType.class, TestClassType.class, value);
      }
  
  }
  </code></pre>