3

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>&lt;xml&gt;bbb&lt;/xml&gt;</xml>

where i want to get

<xml>bbb</xml>

how can i do it?

EDIT: the problem is that String xml, stores a well formatted XML as a string. so I want this string to be marshaled without escaping the XML characters.

4

1 回答 1

3

如果您想在您的 Java 模型中存储一个 XML 片段String,那么您可以使用@XmlAnyElement带有DomHandler指定的注解来实现这一点。

堆栈溢出示例

于 2013-02-08T17:22:59.493 回答