title: JAXB DOM Node unmarshalling omits elements
body: <p>I'm unmarshalling some XML from <a href="http://www.opengeospatial.org/standards/wfs" rel="nofollow">OGC</a> and running into a problem where not all of the elements make it into the final object.</p>
  
  <p>Here is the example XML</p>
  
  <pre><code>  &lt;?xml version="1.0"?&gt;
      &lt;wfs:CreateStoredQuery xmlns:wfs="http://www.opengis.net/wfs/2.0"
      xmlns:fes="http://www.opengis.org/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:myns="http://www.someserver.com/myns"
      xsi:schemaLocation="http://www.opengis.net/wfs/2.0
  http://schemas.opengis.net/wfs/2.0/wfs.xsd"
      service="WFS" version="2.0.0"&gt;
           &lt;wfs:StoredQueryDefinition id="urn:StoredQueries:FeaturesInPolygon"&gt;
          &lt;wfs:Title&gt;Features In Polygon&lt;/wfs:Title&gt;
          &lt;wfs:Abstract&gt;Find all the features in a Polygon.&lt;/wfs:Abstract&gt;
          &lt;wfs:Parameter name="AreaOfInterest" type="gml:PolygonType" /&gt;
          &lt;wfs:QueryExpressionText returnFeatureTypes="myns:Parks"
              language="urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression"
              isPrivate="false"&gt;
              &lt;wfs:Query typeNames="myns:Parks"&gt;
                  &lt;fes:Filter&gt;
                      &lt;fes:Within&gt;
                          &lt;fes:ValueReference&gt;geometry&lt;/fes:ValueReference&gt;
                          &lt;gml:Polygon&gt;
                              &lt;gml:exterior&gt;
                                  &lt;gml:LinearRing&gt;
                                      &lt;gml:posList&gt;0 0 100 0 100 100 0 100 0 0&lt;/gml:posList&gt;
                                  &lt;/gml:LinearRing&gt;
                              &lt;/gml:exterior&gt;
                          &lt;/gml:Polygon&gt;
                      &lt;/fes:Within&gt;
                  &lt;/fes:Filter&gt;
              &lt;/wfs:Query&gt;
          &lt;/wfs:QueryExpressionText&gt;
      &lt;/wfs:StoredQueryDefinition&gt;
  &lt;/wfs:CreateStoredQuery&gt;
  </code></pre>
  
  <p>Here is the XSD for the offending region</p>
  
  <pre><code>&lt;xsd:complexType name="StoredQueryDescriptionType"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element ref="wfs:Title" minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:element ref="wfs:Abstract" minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:element ref="ows:Metadata" minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:element name="Parameter"
              type="wfs:ParameterExpressionType"
              minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:element name="QueryExpressionText"
              type="wfs:QueryExpressionTextType"
              minOccurs="1" maxOccurs="unbounded"/&gt;
      &lt;/xsd:sequence&gt;
      &lt;xsd:attribute name="id" type="xsd:anyURI" use="required"/&gt;
  &lt;/xsd:complexType&gt;
  &lt;xsd:complexType name="ParameterExpressionType"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element ref="wfs:Title" minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:element ref="wfs:Abstract" minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:element ref="ows:Metadata" minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xsd:sequence&gt;
      &lt;xsd:attribute name="name" type="xsd:string" use="required"/&gt;
      &lt;xsd:attribute name="type" type="xsd:QName" use="required"/&gt;
  &lt;/xsd:complexType&gt;
  &lt;xsd:complexType name="QueryExpressionTextType" mixed="true"&gt;
      &lt;xsd:choice&gt;
          &lt;xsd:any namespace="##other" processContents="skip"
              minOccurs="0" maxOccurs="unbounded"/&gt;
          &lt;xsd:any namespace="##targetNamespace" processContents="skip"
              minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xsd:choice&gt;
      &lt;xsd:attribute name="returnFeatureTypes"
          type="wfs:ReturnFeatureTypesListType" use="required"/&gt;
      &lt;xsd:attribute name="language" type="xsd:anyURI" use="required"/&gt;
      &lt;xsd:attribute name="isPrivate" type="xsd:boolean" default="false"/&gt;
  &lt;/xsd:complexType&gt;
  &lt;xsd:simpleType name="ReturnFeatureTypesListType"&gt;
      &lt;xsd:list itemType="xsd:QName"/&gt;
  &lt;/xsd:simpleType&gt;
  </code></pre>
  
  <p>The part that is messing up is the xsd:any under QueryExpressionTextType. It has the attribute processContents="skip" which causes JAXB to create DOM objects instead of the JAXB classes. I figured I would just use the JAXB context to unmarshall the DOM Nodes afterwards, here is some example code for what I tried.</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      InputStream in = new FileInputStream("test/res/createQuery.xml");
      JAXBContext context = JAXBContext.newInstance(
              net.opengis.gml.v_3_2_1.ObjectFactory.class,
              net.opengis.wfs.v_2_0_0.ObjectFactory.class,
              net.opengis.filter.v_2_0_0.ObjectFactory.class);
      Unmarshaller unmarshaller = context.createUnmarshaller();
      JAXBElement&lt;?&gt; jElem = (JAXBElement&lt;?&gt;) unmarshaller.unmarshal(in);
      CreateStoredQueryType create = (CreateStoredQueryType) jElem.getValue();
      List&lt;StoredQueryDescriptionType&gt; descriptions = create
              .getStoredQueryDefinition();
      StoredQueryDescriptionType desc = descriptions.get(0);
      List&lt;QueryExpressionTextType&gt; texts = desc.getQueryExpressionText();
      QueryExpressionTextType text = texts.get(0);
      List&lt;Object&gt; contents = text.getContent();
      Node node = (Node) contents.get(0);
      jElem = (JAXBElement&lt;?&gt;) unmarshaller.unmarshal(node);
      QueryType query = (QueryType) jElem.getValue();
      // prints[{http://www.someserver.com/myns}Parks]
      System.out.println(query.getTypeNames());
      // is false
      System.out.println(query.isSetAbstractSelectionClause());
  }
  </code></pre>
  
  <p>It gets the Query object out just fine (including the typeNames attribute). But it skips the Filter object. The Filter object inherits from AbstractSelectionClause, so it should be set in the returned object, but it isn't. I debugged and checked the DOM Element and confirmed that the Filter is in the DOM tree.</p>
  
  <p>To get the JAXB objects I'm using, I checked out the SVN repository from the <a href="http://java.net/projects/ogc/sources" rel="nofollow">jvnet OGC project</a>, I did have to compile the WFS 2.0 schemas, but the Filter and GML schemas were already done.</p>
  
  <p>Any insight would be greatly appreciated.</p>