【问题标题】:Element 'title' is already used with @org.simpleframework.xml.ElementList元素“标题”已与 @org.simpleframework.xml.ElementList 一起使用
【发布时间】:2016-07-31 10:40:45
【问题描述】:

我正在使用 SimpleXml api 反序列化 xml。
但收到异常

###异常:

元素 'title' 已与字段 ' 上的 @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=title, required=true, type=void) 一起使用第 1 行的 citationList' private java.util.List com.example.app.Entity.Citations.citationList

###我的 Xml:
<citations>
 <title>xyz xyz</title>
 <title>xyz xyz</title>
 <title>xyz xyz</title>
 <title>xyz xyz</title>
 <title>xyz xyz</title>
 <title>xyz xyz</title>
</citations>

###我的班级:引文

@Root(name = "citations")
public class Citations {

    @ElementList(name = "title")
    private List<String> citationList;


    public List<String> getCitationList(){
        return citationList;
    }

    public void setCitationList(List<String> citationList) {
        this.citationList = citationList;
    }
}

请帮我解决这个问题,我如何使用 SimpleXml api 对其进行反序列化。 我应该在课堂上使用什么注释。我收到了与上面提到的相同的 xml。

【问题讨论】:

    标签: java android xml-parsing xml-deserialization simple-framework


    【解决方案1】:

    我得到了答案,使用注释属性如下。

    @Root(name = "引文") 公共类引文{

        public Citations(){}
        @ElementList(inline = true,entry = "citation")
        private List<String> citationList;
    
        public List<String> getCitationList() {
            return citationList;
        }
    
        public void setCitationList(List<String> citationList) {
            this.citationList = citationList;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      • 2023-03-11
      • 1970-01-01
      • 2011-09-04
      相关资源
      最近更新 更多