Reputation:
suppose i have an object with String property that has an XML string. like:
class myObject {
String xml;
@XmlElement(name = "xml", type = String.class)
public String getXml() {
return xml;
}
public void setXml(String xml) {
this.xml = xml;
}
}
i set an XML String to this property - such as
myObject.setXml("<xml>bbb</xml>");
now i want to marshal it using JAXB and i get:
<xml><xml>bbb</xml></xml>
where i want to get
<xml>bbb</xml>
how can i do it?
Upvotes: 2
Views: 2885
Reputation: 116512
If you want to output pre-constructed XML (not just xml serialized as Strings, which is what JAXB correctly gives you), you better feed it DOM Element. Otherwise JAXB can not force XML generator to dump random text without proper escaping.
Where do you get XML? If it comes as DOM stuff this should be relatively easy.
Upvotes: 0
Reputation: 403481
You use the @XmlAnyElement for this. However, first you need to convert your XML string into a DOM structure, and inject that into your model, rather than the raw XML String.
Upvotes: 2