使用“已使用元素”解析XML Feed模具

我正在尝试使用Android中的SimpleXML解析XML Feed: http : //backend.deviantart.com/rss.xml? type = defiation&q = by%3Aspyed+sort%3Atime+meta% 3Aall

样品在这里:

   DeviantArt: spyed's http://www.deviantart.com/?order=5&q=by%3Aspyed DeviantArt RSS for sort:time by:spyed en-us Copyright 2015, DeviantArt.com Thu, 20 Aug 2015 07:45:31 PDT DeviantArt.com http://blogs.law.harvard.edu/tech/rss http://sofzh.miximages.com/java/android-192.png    Happy 15th Birthday! http://spyed.deviantart.com/journal/Happy-15th-Birthday-552416478 http://spyed.deviantart.com/journal/Happy-15th-Birthday-552416478 Sun, 09 Aug 2015 01:41:54 PDT Happy 15th Birthday!  nonadult journals/personal spyed http://sofzh.miximages.com/java/spyed.gif Copyright 2015 spyed   In April I wrote a post reflecting on my 15 years at DeviantArt, since the project began in April of 2000 and was launched to the public on August 7th. I went back and re-read what I wrote, and wow, speaking of audacious I'm pretty hardcore in this post. I write from my heart sometimes and then I hit post and that's that. So for our official 15th Birthday I wanted to re-share a link to that post:<br /><br />And then today, I wrote this reflection for you as a toast &amp; thanks for all the llamas:<br /><br />Happy 15th Birthday DeviantArt! We are evolving, and soon we will be able to share exactly how you can be a part of our transformation, ensuring that the De    The Floor is Open http://spyed.deviantart.com/journal/The-Floor-is-Open-548845475 http://spyed.deviantart.com/journal/The-Floor-is-Open-548845475 Sat, 25 Jul 2015 11:38:46 PDT The Floor is Open  nonadult journals/personal spyed http://sofzh.miximages.com/java/spyed.gif Copyright 2015 spyed   Happy Saturday! I'm hanging out at home, so I thought I'd have an open conversation. Post anything, I'll reply. It's about 11:30am, I'll be in front of this thing for two hours before I go to my god daughters 7th birthday party! Yay!<br /><br />If you're wondering what we're up to, check out the DeviantArt Timeline ( http://www.deviantart.com/timeline/ ) -- It might compel you to ask some questions. Or, if there's anything you've been wondering about, ask!<br /><br />Here's some food for thought to get you started about the overall state of DeviantArt:<br /><br />Our team focuses on two things that matter most to us, the first is our mission to Entertain, Inspire &amp; Em   ... etc .... 

但我收到以下错误:

 08-13 15:55:38.529: W/System.err(1437): org.simpleframework.xml.core.PersistenceException: Element 'title' is already used with @org.simpleframework.xml.Element(data=false, name=title, required=false, type=void) on field 'title' public java.lang.String com.example.feedreader.SimpleRss$Channel$RssItem.title at line 1 

我注意到有两个不同级别的title标签,但我不确定如何在代码中进行区分。

这就是我所拥有的:

 @Root(name = "rss", strict = false) public class SimpleRss implements FeedRoot { @Root(name = "channel") public static class Channel { @Element(name = "title", required = false) public String title = ""; @Attribute(name = "href", required = false) @ElementList(entry = "link", inline = true, required = false) private List links; @Element(name = "description", required = false) @Namespace(prefix = "") public String description = ""; @Element(name = "pubDate", required = false) public String pubDate = ""; @Element(name = "event_link", required = false) public String event_link = ""; @Root(name = "item") public static class RssItem implements SimpleFeedItem { public String parent = ""; public String feedUrl = null; public Date date = null; @Element(name = "title", required = false) public String title = ""; @Element(name = "link", required = false) public String link = ""; @Element(name = "event_link", required = false) public String event_link = ""; @Element(name = "description", required = false) public String description = ""; @Element(name = "pubDate", required = false) public String pubDate = ""; @Path("enclosure") @Attribute(name = "url", required = false) public String enclosureUrl = ""; @Path("enclosure") @Attribute(name = "type", required = false) public String enclosureType = ""; @Override public String getTitle() { return title; } @Override public String getDescription() { return description; } @Override public String getLink() { return link; } @Override public String getEventLink() { return event_link; } @Override public String getAdditional() { return parent; } @Override public String getPubDate() { return pubDate; } @Override public String getFeedUrl() { return feedUrl; } @Override public void setFeedUrl(String url) { feedUrl = url; } @Override public void setDate(Date date) { this.date = date; } @Override public Date getDate() { return date; } @Override public String getPictureUrl() { if (DataUtils.isEmpty(enclosureType)) { return null; } else if (SimpleFeedItem.SupportedFeedImageTypes .contains(enclosureType.toLowerCase(Locale.ENGLISH))) { return enclosureUrl; } else { return null; } } } @ElementList(inline = true, required = false) public List rssItems = J.newArrayList(); } @Element(name = "channel") public Channel channel; @Override public List getItems() { List items = J.newArrayList(); if (channel != null && channel.rssItems != null) { for (RssItem item : channel.rssItems) { String title = channel.title; if (title == null) { title = ""; } item.parent = title.intern(); items.add(item); } } return items; } @Override public String getTitle() { if (channel == null) { return ""; } else { return channel.title; } } } 

我试过评论一下

 @Element(name = "title", required = false) public String title = ""; 

Channel类中我得到了同样的错误。 如果我只是重命名它。

但是,如果我对RssItem类中的RssItem做同样的RssItem ,它会起作用,但是我没有得到项目的标题。

谢谢!

这解决了这个问题:

删除这个:

 @Element(name = "title", required = false) 

用。。。来代替:

 //inside the inner class RssItem @Path("title") @Text(required=false) public String title = ""; 

对于获得exception的任何其他字段,应该重复此操作。

看来是用的

 @Element(name = "title", required = false, inLine=true) public String title = ""; 

将解决您的问题,如此处所示。