I am trying to wrap a set of classes based on Simple XML (Java Serializer) around an RSS feed. Sample delivery
<?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 I get when running the code is
org.simpleframework.xml.core.PersistenceException: Element 'link' declared twice at line 24
And the error is true, because the name of a particular element occurs twice in xml, but in different ways.
The first link element is here.
<link>http://www.codinghorror.com/blog/</link>
Right below the channel tag. And then the next link tag is again in the Channel section 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 the Channel.java class, I cannot have two variables with the same name. I tried changing the variable name to blogLink and tried to give the 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 that something is missing here, but I can’t put it on him. I would appreciate any help with 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; }
Communication 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 changed the class names, but still points to the same error.