解组
>在 XML 数据中
我有一些 xml 数据,我试图将其解组为 java 对象,其中一个元素包含
元素:
<details>
<para>
Line Number One
<br/>
Line Number Two
</para>
</details>
在我的详细信息 java 对象中,我有:
class Details {
@XmlElement(name="para")
private List<String> paragraphs;
}
问题是唯一的元素段落列表中是“第二行”。有谁知道我该如何处理这个问题?
I have some xml data I'm trying to unmarshall into java objects and one of the elements contains <br/>
elements:
<details>
<para>
Line Number One
<br/>
Line Number Two
</para>
</details>
In my Details java object I have:
class Details {
@XmlElement(name="para")
private List<String> paragraphs;
}
The problem is that the only element in the paragraphs list is 'Line Number Two'. Does anyone know how I can deal with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
表示混合内容@XmlMixed
如下(请注意,它应用于类本身的内容而不是其元素,因此您需要一个附加类):paragraphs
属性将包含String
用于文本行,Element
用于 XML 元素。You can represent mixed content with
@XmlMixed
as follows (note that it's applied to content of a class itself rather than to its element, thus you need an additional class):paragraphs
property will containString
s for text lines andElement
s for XML elements.在这种情况下,XML 的格式不正确。将整个数据放入 CDATA 内的标签内以避免此问题。请参阅 - http://www.w3schools.com/xml/xml_cdata.asp
In that case the XML is not formed correctly. Put the entire data inside the tags within CDATA to avoid this issue. Refer - http://www.w3schools.com/xml/xml_cdata.asp
您可以将
@XmlAnyElement
与DomHandler
一起使用,将 XML 文档的片段保留为String
。下面是演示如何执行此操作的完整示例的链接:You could use
@XmlAnyElement
along with aDomHandler
to preserve fragments of the XML document as aString
. Below is a link to a complete example demonstrating how to do this: