SimpleXML parsing RSS Feed



i try to parse an RSS Feed using SimpleXML.



<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://ift.tt/r5ut6F">
<channel>
<title>Nachrichten aus Mannheim - Mannheimer Morgen - Morgenweb</title>
<description></description>
<link>http://ift.tt/1onoSRF;
<atom:link href="http://ift.tt/Mjf1Ku" rel="self" type="application/rss+xml" />
<language>de-de</language>
<ttl>1800</ttl>
<item>
<title>Parteien verschieben Aubuckel-Entscheidung</title>
...


The Feed contains two elements, one without namespace one with .

SimpleXml has problem to parse this. I always get:



Caused by: org.simpleframework.xml.core.PersistenceException: Duplicate annotation of name 'link' on field 'link' java.lang.String com.packagename.Channel.link


My Channel Class looks like this:



@Root(strict = false)
public class Channel {

@Element
String title;

@Element(required = false)
String link;

@Namespace(reference="http://ift.tt/r5ut6F", prefix="atom")
@Element(name = "link")
String atomLink;


@Element
String language;

@Element
int ttl;


@Element(required = false)
String description;


I played with the @Namespace Annotation, but never got it working. And Documentation about this problem rare. Anyone can guide me how an RSS Feed can be parsed with SimpleXml ?


No comments:

Post a Comment