title: In JAXB or Xstream is it possible to Filter out certain Child Elements on Type/value during unmarshall
body: <p>Hope everyone is well, quick question to see if anyone has any feedback. </p>
  
  <p>I was experimenting with both JaxB and Xstream over last two days. I was basically using the XML libraries to marshal and unmarshal XML to / from Java objects. Now this was a very simple task which I got working very quickly. However, the XML I want to unmarshal into a list of Java objects is very long and contains many child elements that could be ignored and not put into the list of java objects. 
  For example the xml would look similar to: </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Tables&gt;
      &lt;Table1&gt;
          &lt;TYPE&gt;Test1&lt;/TYPE&gt;
          &lt;DATE&gt;2014-01-16&lt;/DATE&gt;
          &lt;FLAG&gt;True&lt;/FLAG&gt;
      &lt;/Table1&gt;
      &lt;Table1&gt;
          &lt;TYPE&gt;Test2&lt;/TYPE&gt;
          &lt;DATE&gt;2014-01-15&lt;/DATE&gt;
          &lt;FLAG&gt;False&lt;/FLAG&gt;
      &lt;/Table1&gt;
      &lt;Table1&gt;
          &lt;TYPE&gt;Test1&lt;/TYPE&gt;
          &lt;DATE&gt;2014-01-14&lt;/DATE&gt;
          &lt;FLAG&gt;True&lt;/FLAG&gt;
      &lt;/Table1&gt;
  &lt;/Tables&gt;
  </code></pre>
  
  <p>So I would like the library to iterate through all the xml elements and unmarshal into a list of java objects which so far works, however as it iterates I would like to add additional functionality to check the Type and Flag element values, if TYPE value equals Test2 and or if Flag value equals False to ignore this child element all together and not include it in the finished list of Java objects. Does anyone know if this is possible with either JaxB or Xstream? Alternatively, can anyone suggest maybe a better approach to accomplish this which requires minimum code and manual parsing. </p>
  
  <p>I have been looking at ValidationEventHandler and XmlAdapter in JaxB but I do not think these will allow me do what I want. I got close with the Xmldapter however the unmarshal has to return either null or an object for each xml child element it processes, it also changed the xml syntax to attribute form i.e TYPE = "Test1" etc which I did not see any way of altering. </p>
  
  <p>Xstream allows you to implement a Converter which has a canConvert method, however this only works on Class type, and not child element type which I weant to check for each child element. Had a look at MapperWrapper wrapMapper method which can be overloaded in Xstream, but it only shows element attribute name, i.e FLAG and does not show value, also if it did show value I do not see anyway of telling the function to ignore child root element and all attributes for said child. </p>
  
  <p>Anyway, that's my two cent. Any advice? </p>