class exception when parsing rss feed

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

class exception when parsing rss feed

anilno2
My apologies if this has been asked before; I tried searching for an answer but am getting frustrated...

I have a rss feed that looks this:
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
  <channel>
  <title>title</title>
        <link>link</link>
        <description>n/a</description>
        <language>en-us</language>
        <lastBuildDate>Mon, 25 Jan 2002 13:29:02 GMT</lastBuildDate>
        <generator>any text</generator>
                <item>
                        <title>some text.</title>
                </item>
                <item>
                        <title>more text.</title>
                </item>
        </channel>
</rss>

Here are my pojos:
public class News {
        private List<Channel> channel;
        private String version;
//all getters and setters
}

public class Channel {
        private String title;
        private String link;
        private String description;
        private String language;
        private String lastBuildDate;
        private String generator;
        private List<Item> item;
//all getters and setters
}

public class Item {
        private String title;
        private String link;
        private String description;
        private String pubDate;
//all getters and setters
}

and implementation:
XStream xstream = new XStream(new DomDriver());
News newsresponse = new News();
String sResponse = "";

xstream.alias("rss",News.class);
xstream.alias("channel",Channel.class);
xstream.alias("item",Item.class);
xstream.addImplicitCollection(Channel.class, "item");

try {
        URL url = new URL("http://xxxx/abc.xml");
        URLConnection urlc = url.openConnection();

        InputStreamReader isr = new InputStreamReader(urlc.getInputStream());
        int isrCount = isr.read();
        while(isrCount != -1){
                sResponse += String.valueOf((char) isrCount);
                isrCount = isr.read();
        }
        isr.close();
        xstream.fromXML(sResponse, newsresponse);
} catch (FileNotFoundException e) {
        e.printStackTrace();
}catch (MalformedURLException e) {
        e.printStackTrace();
} catch (IOException e) {
        e.printStackTrace();
}

I keep getting the below exceptions:
Encountered com.thoughtworks.xstream.converters.ConversionException: title : title : title : title

can someone pls help me...

thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: class exception when parsing rss feed

Jörg Schaible-2
Hi,

anilno2 wrote:

> My apologies if this has been asked before; I tried searching for an
> answer but am getting frustrated...
>
> I have a rss feed that looks this:
> <?xml version="1.0" encoding="iso-8859-1"?>
> <rss version="2.0">
>   <channel>
>   <title>title</title>
> <link>link</link>
> <description>n/a</description>
> <language>en-us</language>
> <lastBuildDate>Mon, 25 Jan 2002 13:29:02 GMT</lastBuildDate>
> <generator>any text</generator>
>                 <item>
>                         <title>some text.</title>
>                 </item>
>                 <item>
>                         <title>more text.</title>
>                 </item>
>         </channel>
> </rss>
>
> Here are my pojos:
> public class News {
> private List<Channel> channel;
> private String version;
> //all getters and setters
> }
>
> public class Channel {
> private String title;
> private String link;
> private String description;
> private String language;
> private String lastBuildDate;
> private String generator;
> private List<Item> item;
> //all getters and setters
> }
>
> public class Item {
> private String title;
> private String link;
> private String description;
> private String pubDate;
> //all getters and setters
> }
>
> and implementation:
> XStream xstream = new XStream(new DomDriver());
> News newsresponse = new News();
> String sResponse = "";
>
> xstream.alias("rss",News.class);
> xstream.alias("channel",Channel.class);
> xstream.alias("item",Item.class);
> xstream.addImplicitCollection(Channel.class, "item");
>
> try {
> URL url = new URL("http://xxxx/abc.xml");
> URLConnection urlc = url.openConnection();
>
> InputStreamReader isr = new InputStreamReader(urlc.getInputStream());
> int isrCount = isr.read();
> while(isrCount != -1){
> sResponse += String.valueOf((char) isrCount);
> isrCount = isr.read();
> }
> isr.close();
> xstream.fromXML(sResponse, newsresponse);
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> }catch (MalformedURLException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> I keep getting the below exceptions:
> Encountered com.thoughtworks.xstream.converters.ConversionException: title
> : title : title : title
>
> can someone pls help me...

From the first look, it seems right. However, have you tried to generate the
XML? It will give you an immediate impression, what is different concerning
the XML you're trying to reed.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: class exception when parsing rss feed

Yahya
This post has NOT been accepted by the mailing list yet.
In reply to this post by anilno2
Hi anilno2,

I am facing the same error right now, i know it's been 2 years of this post but i didn't find a way to fix it. So how did you solve this issue? Can you share your solution please?

I basicly try to read rss with xstream...

Thanks in advance.