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

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

问题描述

我有一个像这样的表单的 XML:

Text

Text

如何使用 JAXB 注释将所有内容映射到字符串值.

公共类内容{字符串值;}

所以 Content.value = "

Text

Text

"?

解决方案

您可以使用 @XmlAnyElement 注释并指定一个 DOMHandler 来将 DOM 片段转换为/从 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;
}

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

解决方案

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

For a Complete Example

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

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