I had a problem while unmarshalling XML with mixed content. The space is lost. XML looks like this:
<text>rooms in <g>the</g> <g>Eldorado Hotel</g> on Broadway have a jacuzzi</text>
This is not tied to:
- "rooms in" (with final space)
- an object with a value of 'the'
- object with the value 'Eldorado Hotel'
- "There is a jacuzzi on Broadway" (with initial space).
Everything is fine, but I skip the space between the two tags. I need to save this space!
A simplified comparison will look something like this:
@XmlTransient
public abstract class AbstractText {
private List words;
@XmlMixed
@XmlElementRefs({
@XmlElementRef(type = WordGroup.class, required = false),
@XmlElementRef(type = Word.class, required = false)
})
public List getWords() {
if (words == null) words = new ArrayList();
return words;
}
public void setWords(List words) {
this.words = words;
}
}
@XmlRoot
public class Text extends AbstractText{
}
The mapping is performed not like in this case, but in the XML file (each class inheriting from AbstractText can have different children.
Real display:
<java-type name="dp.dc.exercise.model.Text">
<java-attributes>
<xml-element-refs java-attribute="words" xml-mixed="true">
<xml-element-ref type="dp.dc.exercise.model.text.Word" required="false"/>
<xml-element-ref type="dp.dc.exercise.model.text.WordGroup" required="false"/>
</xml-element-refs>
</java-attributes>
</java-type>
and works great anyway, but when there are two tags one by one.
Any help would be greatly appreciated :)