简单的框架:重复标注(不同的命名空间) [英] Simple-Framework: Duplicate annotation (different namespace)

查看:196
本文介绍了简单的框架:重复标注(不同的命名空间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想用简单的框架用Java来解析一个RSS feed。
我有2个元素具有相同名称的问题,但其中一人都分配一个命名空间。
下面是一个示例XML:

I have an Rss feed that I'd like to parse in Java using Simple Framework. I have problems with 2 elements with the same name, but one of them has a namespace assigned. Here is an example xml:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/">
    <item>
        <title>Regular Titel</title>
        <dc:title>Dc Titel</dc:title>
    </item>
</rss>

目前我Item.class看起来是这样的:

Currently my Item.class looks like this:

@Root
public class Item {

    @Namespace(reference = "http://purl.org/dc/elements/1.1/", prefix = "dc")
    @Element(name="title")
    public String dcTitle;

    @Element
    public String title;
}

这显然导致的PersistenceException(重名现场'标题''标题'......的注释),但我真的不知道应该怎么做。可能有人请帮我算出这个!

This obviously causes a PersistenceException (Duplicate annotation of name 'title' on field 'title'....), but i don't really know how I should do this. Could someone please help me to figure this out!

更新

Althought解决方案的工作,我现在有序列化对象的问题。该命名空间,我声明,没有分配给输出的XML元素。

Althought the solution works, I now have problems serializing the objects. The namespaces, that I declare, are not assigned to the elements in the output xml.

推荐答案

尝试

@Root
public class Item {

    @Namespace(reference = "http://purl.org/dc/elements/1.1/", prefix = "dc")
    @Path("title[1]")
    @Text
    public String dcTitle;

    @Path("title[2]")
    @Text
    public String title;
}

这篇关于简单的框架:重复标注(不同的命名空间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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