ievgen
ievgen

Reputation: 1101

How to map the enclosing content of an XML tag with JAXB?

I'm trying to make JAXB to capture the tag's content into some property of Java Bean. This is an example of XML message:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Film Id="5705" Title="Some title" TitleOrig="Original title">
     The description follows
</Film>

I've come up with the following Java Bean for this XML message, but I'm finding difficulties with mapping the film's description.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Film")
@XmlRootElement(name = "Film")
public class Film
{
    @XmlAttribute(name = "Id")
    public Integer id;
    @XmlAttribute(name = "Title")
    public String title;
    @XmlAttribute(name = "TitleOrig")
    public String titleOrig;

    public String description; // How to annotate this property ?
}

Can anybody point me in the right direction ? Is this a valid XML ? Cause I failed to find any solutions to this task on the internet.

Upvotes: 3

Views: 267

Answers (1)

skaffman
skaffman

Reputation: 403501

Use @XmlValue, i.e.

@XmlValue
public String description; 

Upvotes: 5

Related Questions