Format Conversion

Yarfraw provides a unified data model for all the feed formats that it supports. This means you can easily write a conversion utility to convert between different feed formats. Simply reads in the original format, and then write it to a file using a different format setting. For example, to convert a Rss 2.0 feed to Rss 1.0:

    FeedReader r = new FeedReader("rss20.xml");
    ChannelFeed c = r.readChannel();
    
    File f = File.createTempFile("rss10", ".xml");
    FeedWriter w = new FeedWriter(f);
    w.setFormat(FeedFormat.RSS10);
    w.writeChannel(c);
    
    //of course, you can read the converted feed
    r.setFormat(FeedFormat.RSS10);
    r.setFile(f);
    ChannelFeed c2 = r.readChannel();
  

There are a few things you need to be aware of:

  1. Some fields are format specific, so if you convert a feed to a different format and then convert it back, some information could be lost.
  2. Yarfraw only checks the validity of the date string when it writes a feed, it does not check the data format when it reads (more details here ). That means if you read in an ATOM 1.0 feed and write it in RSS 2.0 format, the date format will be automatically converted from ISO 8601 to RFC 822.

JAXB Marshalling/UnMarshalling

The classes in the following three packages are generated by JAXB and are intended to be used internally by Yarfraw:

  • yarfraw.generated.rss20.elements
  • yarfraw.generated.rss10.elements
  • yarfraw.generated.atom10.elements

However, there's nothing stopping you from using them if you want to. You can use them to build the JAXB binding objects yourself and marshal them. Or you can use them to unmarshall an xml and deal with the binding object directly. To do that, use the following JAXB contexts:

  
  CommonUtils.RSS20_JAXB_CONTEXT;
  CommonUtils.RSS10_JAXB_CONTEXT;
  CommonUtils.ATOM10_JAXB_CONTEXT;
  
  //and use them to get an unmarshaller
  Unmarshaller u = JAXBContext.newInstance(CommonUtils.RSS20_JAXB_CONTEXT).createUnmarshaller();

For more details, I encourage to take a look at the Javadoc . Also check out the FAQ section for more insights about this API.