I have been trying to wrap a set of classes based on Simple XML (Java Serializer) around a RSS Feed. The sample feed is
<?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>
The error that I am getting while running the code is
org.simpleframework.xml.core.PersistenceException: Element 'link' declared twice at line 24
And the error is fair enough because the particular element name occurs twice in the xml but in different ways.
The first link element is here
<link>http://www.codinghorror.com/blog/</link>
Its directly under the Channel tag. And then the next link tag is again under Channel in the following format
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codinghorror" />
In Channel.java class I cannot have two variables with the same name link. I tried changing a variable name to blogLink and tried giving name in the Element annotation and Eclipse gave me this error
Change was
@Element("name=link")
Result is
The attribute value is undefined for the annotation Element
I know I am missing something here but I am not able to put my finger on it. I would appreciate any help on this.
UPDATE
Channel Class
@Element(name="link")
@Namespace(reference="http://www.w3.org/2005/Atom",prefix="atom")
private atomlink atomlink;
public atomlink getAtomLink() {
return atomlink;
}
Link Class
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;
}
}
I have changed the class names and yet it still points to the same error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…