rss reader - Parse custom rss tags using Rome API -


i trying use rome parsing rss feeds. 1 of rss feeds says specifies 0.91 version , no custom xml namespace defined entries still have custom element in them. can use rome parse such custom tags without defined namespace?

thanks.

yes. need write custom parser it.

let's want handle elements customstring , customdate. start extending item class store custom elements.

package com.example;  import com.sun.syndication.feed.rss.item; import java.util.date;  public class customitem extends item {      private string _customstring;     private date _customdate;      public string getcustomstring() {         return _customstring;     }      public void setcustomstring(string customstring) {         _customstring = customstring;     }      public date getcustomdate() {         return _customdate;     }      public void setcustomdate(date customdate) {         _customdate = customdate;     }  } 

then write parser. need handle standard elements want parse.

package com.example;  import com.example.customitem;     import com.sun.syndication.feed.rss.item; import com.sun.syndication.io.wirefeedparser; import com.sun.syndication.io.impl.dateparser; import com.sun.syndication.io.impl.rss091userlandparser; import org.jdom.element;  public class customparser extends rss091userlandparser implements wirefeedparser {      public customitem parseitem(element rssroot, element eitem) {         customitem customitem = new customitem();          // standard elements         item standarditem = super.parseitem(rssroot, eitem);         customitem.settitle(standarditem.gettitle());         customitem.setdescription(standarditem.getdescription());          // non-standard elements         element e = eitem.getchild("customstring", getrssnamespace());         if (e != null) {             customitem.setcustomstring(e.gettext());         }          e = eitem.getchild("customdate", getrssnamespace());         if (e != null) {             customitem.setcustomdate(dateparser.parsedate(e.gettext()));         }          return customitem;     }  } 

finally need define parser in rome.properties file along parsers other type of feed want handle.

# feed parser implementation classes # wirefeedparser.classes=com.example.customparser 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -