Really Simple Syndication (RSS) is a web technology enabling the user to subscribe to a source of information. For example, a user might be interested in the latest news headlines. His favorite news website provides a feed with the latest headlines using RSS. By using the feed in RSS-reader software, the user can quickly get a overview of the latest headlines. Also he can get notified when a new article is published. As RSS is just another XML standard, APEX is capable of generating one.
In this example we will build a feed of products, based on the standard demo table demo_products_info. Start by creating a new page with as page alias "RSS". The page should be public, because we want to allow the user to access an application process without authentication. Place the following text in the HTML header:
<link rel="alternate" title="Products" type="application/rss+xml" href="http://XXX/apex/f?p=&APP_ID.:&APP_PAGE_ID.:0:APPLICATION_PROCESS=getrss::::" />
Replace the XXX with the appropriate server address. As the URL suggests we need an application process named getrss. This process will return the RSS feed. Place the following code into the process:
declare
v_xml clob;
v_retval clob := '<?xml version="1.0" encoding="iso-8859-1"?>';
v_blob blob;
begin
select xmlelement("rss"
, xmlattributes('2.0' "version")
, xmlelement("channel"
, xmlforest('Products' "title"
, 'http://XX/f?p=&APP_ID.:1:' "link"
, 'All our products' "description"
, 'nl-nl' "language"
, sysdate "lastBuildDate"
)
, xmlagg(
xmlelement("item"
, xmlforest(product_name "title"
, product_description "description"
, 'http://XX/f?p=&APP_ID.' "link"
)
) order by product_name
)
)
).getclobval()
into v_xml
from demo_product_info;
--
dbms_lob.append(v_retval,v_xml);
--
OWA_UTIL.Mime_Header('text/xml');
--
htp.p('Content-length: ' || to_char(dbms_lob.getlength(v_retval)));
htp.p('Content-Disposition: inline; filename="rss.xml"');
owa_util.http_header_close;
--
v_blob := wwv_flow_utilities.clob_to_blob(v_retval);
--
wpg_docload.download_file(v_blob);
--
end;
Again, replace the XXX with the appropriate address. If the page is run, FireFox will show a RSS-feed picture in the addressbar. Clicking on the picture will show the contents of the demo_products_info table.