Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unmarshalling <br/> in XML data

I have some xml data I'm trying to unmarshall into java objects and one of the elements contains <br/> elements:

<details>
    <para>
        Line Number One
        <br/>
        Line Number Two
    </para>
</details>

In my Details java object I have:

class Details {
    @XmlElement(name="para")
    private List<String> paragraphs;
}

The problem is that the only element in the paragraphs list is 'Line Number Two'. Does anyone know how I can deal with this?

like image 327
James Avatar asked May 21 '26 19:05

James


1 Answers

You can represent mixed content with @XmlMixed as follows (note that it's applied to content of a class itself rather than to its element, thus you need an additional class):

class Details {
    @XmlElement(name="para")
    private Para para;
    ...
}

class Para {
    @XmlMixed
    @XmlAnyElement
    private List<Object> paragraphs;
    ...
}

paragraphs property will contain Strings for text lines and Elements for XML elements.

like image 124
axtavt Avatar answered May 24 '26 13:05

axtavt