JAXB获取元素的所有内容(包括标记和文本) [英] JAXB take all content of element (both tags and text)

查看:128
本文介绍了JAXB获取元素的所有内容(包括标记和文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个forml的XML:< content>< p> Text< / p>< p> Text< / p>< / content>
如何使用JAXB注释将所有内容映射到String值。

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;
}

所以 Content.value =< p>文字< / p>< p>文字< / p>

推荐答案

你可以使用 @XmlAnyElement 注释并指定DOMHandler将DOM片段转换为String值或从String值转换。

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

For完整示例

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

这篇关于JAXB获取元素的所有内容(包括标记和文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆