Simple XML (Java Serializer) に基づく一連のクラスを RSS フィードにラップしようとしています。サンプルフィードは
<?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 で 2 回発生しますが、異なる方法で発生するため、エラーは十分に公平です。
最初のリンク要素はこちら
<link>http://www.codinghorror.com/blog/</link>
Channel タグのすぐ下にあります。そして、次のリンクタグは、次の形式でチャネルの下に再びあります
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codinghorror" />
Channel.java クラスでは、同じ名前のリンクを持つ 2 つの変数を持つことはできません。変数名を blogLink に変更して、Element アノテーションに名前を付けようとしたところ、Eclipse でこのエラーが発生しました
Change was
@Element("name=link")
Result is
The attribute value is undefined for the annotation Element
ここで何かが欠けていることは知っていますが、指を置くことはできません。これについて何か助けていただければ幸いです。
アップデート
チャネル クラス
@Element(name="link")
@Namespace(reference="http://www.w3.org/2005/Atom",prefix="atom")
private atomlink atomlink;
public atomlink getAtomLink() {
return atomlink;
}
リンククラス
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;
}
}
クラス名を変更しましたが、それでも同じエラーを指しています。