JAXB take all content of element (both tags and te

2019-01-26 19:19发布

问题:

I have an XML of a forml like this: <content><p>Text</p><p>Text</p></content> How can I map with JAXB annotations all the content to a String value.

public class Content {
    String value;
}

So Content.value = "<p>Text</p><p>Text</p>"?

回答1:

You can use the @XmlAnyElement annotation and specify a DOMHandler to convert the DOM fragment to/from a String value.

For a Complete Example

  • http://blog.bdoughan.com/2011/04/xmlanyelement-and-non-dom-properties.html


标签: java xml jaxb