解组
>在 XML 数据中

发布于 2024-12-11 17:59:31 字数 417 浏览 0 评论 0原文

我有一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一绘本一梦想 2024-12-18 17:59:31

您可以使用 表示混合内容@XmlMixed 如下(请注意,它应用于类本身的内容而不是其元素,因此您需要一个附加类):

class Details {
    @XmlElement(name="para")
    private Para para;
    ...
}

class Para {
    @XmlMixed
    @XmlAnyElement
    private List<Object> paragraphs;
    ...
}

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):

class Details {
    @XmlElement(name="para")
    private Para para;
    ...
}

class Para {
    @XmlMixed
    @XmlAnyElement
    private List<Object> paragraphs;
    ...
}

paragraphs property will contain Strings for text lines and Elements for XML elements.

愛上了 2024-12-18 17:59:31

在这种情况下,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

眼泪都笑了 2024-12-18 17:59:31

您可以将 @XmlAnyElementDomHandler 一起使用,将 XML 文档的片段保留为 String。下面是演示如何执行此操作的完整示例的链接:

You could use @XmlAnyElement along with a DomHandler to preserve fragments of the XML document as a String. Below is a link to a complete example demonstrating how to do this:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文