我一直在尝试基于简单的XML(Java序列化)围绕RSS源来包装一组类。样品饲料简单的Xml-元素声明的两次错误
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>Coding Horror</title>
<link>http://www.codinghorror.com/blog/</link>
<description>programming and human factors - Jeff Atwood</description>
<language>en-us</language>
<lastBuildDate>Wed, 04 May 2011 20:34:18 -0700</lastBuildDate>
<pubDate>Wed, 04 May 2011 20:34:18 -0700</pubDate>
<generator>http://www.typepad.com/</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<image>
<title>Coding Horror</title>
<url>http://www.codinghorror.com/blog/images/coding-horror-official-logo-small.png</url>
<width>100</width>
<height>91</height>
<description>Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved.</description>
<link>http://www.codinghorror.com/blog/</link>
</image>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codinghorror" />
</channel>
</rss>
,我得到运行代码时是
org.simpleframework.xml.core.PersistenceException: Element 'link' declared twice at line 24
而且由于特定元素名称的XML,但以不同的方式出现两次错误是不够公平的错误。
第一个链接元素在这里直接
<link>http://www.codinghorror.com/blog/</link>
其频道标签下。再下一个链接标记又道下按以下格式
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codinghorror" />
在Channel.java I类不能有相同名称的链接的两个变量。我试图改变一个变量名blogLink并在要素标注试图给人名称和Eclipse给了我这个错误
Change was
@Element("name=link")
Result is
The attribute value is undefined for the annotation Element
我知道我失去了一些东西,但我不能把我的手指上。我将不胜感激任何帮助。
UPDATE
渠道类
@Element(name="link")
@Namespace(reference="http://www.w3.org/2005/Atom",prefix="atom")
private atomlink atomlink;
public atomlink getAtomLink() {
return atomlink;
}
Link类
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;
@Root(name="link")
@Namespace(reference="http://www.w3.org/2005/Atom",prefix="atom10")
public class atomlink {
@Attribute
private String rel;
public String getRel() {
return rel;
}
}
我已经改变了类名,但它仍然指向相同的错误。
这是否解决了?我正试图为simple-xml映射出RSS类。如果你能分享,会很好。 – 2011-05-31 16:16:45
不,我不能。发送邮件到邮件列表并没有得到答复。根据文档命名空间应该做的伎俩,但它不适合我。由于时间是我的一个限制,我用dom xml实现了我自己的自定义rss包装器。 – vikramjb 2011-06-01 03:08:43