Any element that can have both child notes that are text and elements is said to have mixed content. In JAXB this corresponds to the @XmlMixed annotation. @XmlMixed can be used on its own on a collection property (see ORIGINAL ANSWER) or in combination with @XmlAnyElement, @XmlElementRef, or @XmlElementRefs. If the element can be anything you would use @XmlAnyElement, if it is one known element you would use @XmlElementRef and it is more than one known element you use @XmlElementRefs.
Span
If there will be both text and div elements within the same span element you could do the following by annotating a property with both @XmlElementRef and @XmlMixed. The element name specified on the @XmlElementRef annotation must correspond directly to the root element specified for the target class.
@XmlRootElement
public class Span {
List
Div
The metadata for Div is almost identical to the metadata specified for Span.
@XmlRootElement
public class Div {
List items = new ArrayList();
@XmlElementRef(name="span", type=Span.class)
@XmlMixed
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
}
Demo
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Span.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Span span = (Span) unmarshaller.unmarshal(new StringReader("Text