Missing id element

View: New views
2 Messages — Rating Filter:   Alert me  

Missing id element

by Tilman Bender-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I use the following slightly modified sample from feedfetcher to  
obtain a feed and convert
it when it was retrieved. Unfortunately all feeds I created via  
conversion so far made feedvalidator choke:

Source: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fnewsfeed.zeit.de%2F
Converted: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fstud.hs-heilbronn.de%2F%257Etbender%2Fzeit-converted.xml

Source: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.heise.de%2Fnewsticker%2Fheise.rdf
Converted: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fstud.hs-heilbronn.de%2F%257Etbender%2Fheise-converted.xml

Source: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.faz.net%2Fs%2FRub%2FTpl~Epartner~SRss_.xml
Converted: http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fstud.hs-heilbronn.de%2F%257Etbender%2Ffaz-converted.xml

Can't these elements be derived from the RSS documents? Must I create  
these elements in my own code? What am I doing wrong?

kind regards

Till

----------------------------------------------------
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.URL;

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.fetcher.FeedFetcher;
import com.sun.syndication.fetcher.FetcherEvent;
import com.sun.syndication.fetcher.FetcherListener;
import com.sun.syndication.fetcher.impl.FeedFetcherCache;
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedOutput;

/**
  * Hello world!
  *
  */
public class App
{
     public static void main( String[] args )
     {
      boolean ok = false;
                if (args.length==1) {
                        try {
                                URL feedUrl = new URL(args[0]);
                                FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
                                FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache);

                                FetcherEventListenerImpl listener = new FetcherEventListenerImpl();

                                fetcher.addFetcherEventListener(listener);

                                System.err.println("Retrieving feed " + feedUrl);
                                // Retrieve the feed.
                                // We will get a Feed Polled Event and then a
                                // Feed Retrieved event (assuming the feed is valid)
                                SyndFeed feed = fetcher.retrieveFeed(feedUrl);
                                ok = true;
                        }
                        catch (Exception ex) {
                                System.out.println("ERROR: "+ex.getMessage());
                                ex.printStackTrace();
                        }
                }

                if (!ok) {
                        System.out.println();
                        System.out.println("FeedReader reads and prints any RSS/Atom feed  
type.");
                        System.out.println("The first parameter must be the URL of the feed  
to read.");
                        System.out.println();
                }

        }//method main

        static class FetcherEventListenerImpl implements FetcherListener {
                /**
                 * @see com.sun.syndication.fetcher.FetcherListener#fetcherEvent
(com.sun.syndication.fetcher.FetcherEvent)
                 */
                public void fetcherEvent(FetcherEvent event) {
                        String eventType = event.getEventType();
                        SyndFeed feed = event.getFeed();
                        String feedUrl=event.getUrlString();
                        if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
                                System.err.println("\tEVENT: Feed Polled. URL = " +  
event.getUrlString());
                        } else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals
(eventType)) {
                               
                                System.err.println("\tEVENT: Feed Retrieved. URL = " + feedUrl);
                                System.err.println(feedUrl + " has a title: " + feed.getTitle() +  
" and contains " + feed.getEntries().size() + " entries.");
                                feed.setFeedType("atom_1.0");
                                SyndFeedOutput output = new SyndFeedOutput();
                               
                                try {
                                        OutputStreamWriter writer = new OutputStreamWriter(new  
FileOutputStream("converted.xml"), "UTF-8");
                                        output.output(feed,writer);
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (FeedException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        } else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals
(eventType)) {
                                System.err.println("\tEVENT: Feed Unchanged. URL = " +  
event.getUrlString());
                        }
                }
        }

}//class App


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


RE: Missing id element

by Nick Lothian :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The missing ID element is the ID for the feed itself (not an entry). RSS does not contain the information, but generally it's safe to manually set it to the URL the feed came from.

The missing updated elements are because the semantics for RSS dates are underspecified. Sometimes the RSS "date" field means the date it was originally created, sometime it means the last time it was updated.

The simplest thing to do there is to set the Atom updated date to the RSS date. In some cases this could be wrong, though. If you prefer, you can keep records of the contents of each entry, and check for changes each time you recreate the Atom feed.

The other warnings are informational only.

Nick

> -----Original Message-----
> From: Tilman Bender [mailto:tbender@...]
> Sent: Wednesday, 14 October 2009 2:10 AM
> To: users@...
> Subject: Missing id element
>
> Hi,
>
> I use the following slightly modified sample from feedfetcher to
> obtain a feed and convert
> it when it was retrieved. Unfortunately all feeds I created via
> conversion so far made feedvalidator choke:
>
> Source:
> http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fnewsfeed.zeit.d
> e%2F
> Converted:
> http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fstud.hs-
> heilbronn.de%2F%257Etbender%2Fzeit-converted.xml
>
> Source:
> http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.heise.de%2F
> newsticker%2Fheise.rdf
> Converted:
> http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fstud.hs-
> heilbronn.de%2F%257Etbender%2Fheise-converted.xml
>
> Source:
> http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.faz.net%2Fs
> %2FRub%2FTpl~Epartner~SRss_.xml
> Converted:
> http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fstud.hs-
> heilbronn.de%2F%257Etbender%2Ffaz-converted.xml
>
> Can't these elements be derived from the RSS documents? Must I create
> these elements in my own code? What am I doing wrong?
>
> kind regards
>
> Till
>
> ----------------------------------------------------
> import java.io.FileOutputStream;
> import java.io.FileWriter;
> import java.io.IOException;
> import java.io.OutputStreamWriter;
> import java.net.URL;
>
> import com.sun.syndication.feed.synd.SyndFeed;
> import com.sun.syndication.fetcher.FeedFetcher;
> import com.sun.syndication.fetcher.FetcherEvent;
> import com.sun.syndication.fetcher.FetcherListener;
> import com.sun.syndication.fetcher.impl.FeedFetcherCache;
> import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;
> import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
> import com.sun.syndication.io.FeedException;
> import com.sun.syndication.io.SyndFeedOutput;
>
> /**
>   * Hello world!
>   *
>   */
> public class App
> {
>      public static void main( String[] args )
>      {
>       boolean ok = false;
>               if (args.length==1) {
>                       try {
>                               URL feedUrl = new URL(args[0]);
>                               FeedFetcherCache feedInfoCache =
> HashMapFeedInfoCache.getInstance();
>                               FeedFetcher fetcher = new
> HttpURLFeedFetcher(feedInfoCache);
>
>                               FetcherEventListenerImpl listener = new
> FetcherEventListenerImpl();
>
>                               fetcher.addFetcherEventListener(listener);
>
>                               System.err.println("Retrieving feed " +
> feedUrl);
>                               // Retrieve the feed.
>                               // We will get a Feed Polled Event and then a
>                               // Feed Retrieved event (assuming the feed is
> valid)
>                               SyndFeed feed = fetcher.retrieveFeed(feedUrl);
>                               ok = true;
>                       }
>                       catch (Exception ex) {
>                               System.out.println("ERROR: "+ex.getMessage());
>                               ex.printStackTrace();
>                       }
>               }
>
>               if (!ok) {
>                       System.out.println();
>                       System.out.println("FeedReader reads and prints any
> RSS/Atom feed
> type.");
>                       System.out.println("The first parameter must be the
> URL of the feed
> to read.");
>                       System.out.println();
>               }
>
>       }//method main
>
>       static class FetcherEventListenerImpl implements FetcherListener
> {
>               /**
>                * @see
> com.sun.syndication.fetcher.FetcherListener#fetcherEvent
> (com.sun.syndication.fetcher.FetcherEvent)
>                */
>               public void fetcherEvent(FetcherEvent event) {
>                       String eventType = event.getEventType();
>                       SyndFeed feed = event.getFeed();
>                       String feedUrl=event.getUrlString();
>                       if
> (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
>                               System.err.println("\tEVENT: Feed Polled. URL =
> " +
> event.getUrlString());
>                       } else if
> (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals
> (eventType)) {
>
>                               System.err.println("\tEVENT: Feed Retrieved.
> URL = " + feedUrl);
>                               System.err.println(feedUrl + " has a title: " +
> feed.getTitle() +
> " and contains " + feed.getEntries().size() + " entries.");
>                               feed.setFeedType("atom_1.0");
>                               SyndFeedOutput output = new SyndFeedOutput();
>
>                               try {
>                                       OutputStreamWriter writer = new
> OutputStreamWriter(new
> FileOutputStream("converted.xml"), "UTF-8");
>                                       output.output(feed,writer);
>                               } catch (IOException e) {
>                                       // TODO Auto-generated catch block
>                                       e.printStackTrace();
>                               } catch (FeedException e) {
>                                       // TODO Auto-generated catch block
>                                       e.printStackTrace();
>                               }
>                       } else if
> (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals
> (eventType)) {
>                               System.err.println("\tEVENT: Feed Unchanged.
> URL = " +
> event.getUrlString());
>                       }
>               }
>       }
>
> }//class App
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...


IMPORTANT: This e-mail, including any attachments, may contain private or confidential information. If you think you may not be the intended recipient, or if you have received this e-mail in error, please contact the sender immediately and delete all copies of this e-mail. If you are not the intended recipient, you must not reproduce any part of this e-mail or disclose its contents to any other party. This email represents the views of the individual sender, which do not necessarily reflect those of Education.au except where the sender expressly states otherwise. It is your responsibility to scan this email and any files transmitted with it for viruses or any other defects. education.au limited will not be liable for any loss, damage or consequence caused directly or indirectly by this email.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...