I would like to know if/how it is possible to unmarshall an xml document such that the contents of certain know elements will not be treated as xml but rather plain text.
When the below example is run the output is
MessageData [text= and this is just plain]
but I would like it to contain
MessageData [text= This is <b>bold</b>, this is <i>italic</i> and this is just plain]
import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRootElement;
public class JAXBTest {
public static String xml = "<messageData><text>This is <b>bold</b>, this is <i>italic</i> and this is just plain</text></messageData>";
public static void main(String[] args) throws Exception {
JAXBContext context = JAXBContext.newInstance(MessageData.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
System.out.println(unmarshaller.unmarshal(new StringReader(xml)));
}
@XmlRootElement
static class MessageData {
public String text;
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MessageData [text=");
builder.append(text);
builder.append("]");
return builder.toString();
}
}
}
Thanks in advance