Friday, December 24, 2010 at 1:05 AM.
scripting2Suite.server.buildRssJson
on buildRssJson (xmltext, username) { <<Changes <<12/23/10; 9:20:03 AM by DW <<In descriptions, change cr-lf pairs to "\n" and remove all tabs. <<12/22/10; 6:42:48 PM by DW <<Write rss.json based on the content of rss.xml. local (xstruct, jsontext); xml.compile (xmltext, @xstruct); bundle { //clean up the struct local (adrrss, adrchannel, adritem); try {delete (xml.getaddress (@xstruct, "?xml"))}; try {delete (xml.getaddress (@xstruct, "/comment"))}; adrrss = xml.getaddress (@xstruct, "rss"); try {delete (@adrrss^.["/atts"].["xmlns:scripting2"])}; adrchannel = xml.getaddress (adrrss, "channel"); for adritem in adrchannel { if nameof (adritem^) endswith "item" { try { //change scripting2:source to opmlSource local (adrsource = xml.getaddress (adritem, "source")); local (url = adrsource^.["/pcdata"]); delete (adrsource); xml.addvalue (adritem, "opmlSource", url)}; try { //convert the cr-lf pairs in description to \n, remove tabs local (adrdescription = xml.getaddress (adritem, "description")); adrdescription^ = string.replaceall (adrdescription^, "\r\n", "\\n"); adrdescription^ = string.replaceall (adrdescription^, "\t", "")}}}}; <<scratchpad.xstruct = xstruct jsontext = json.decompile (@xstruct); scripting2Suite.writeStaticFile (username, scripting2Suite.data.paths.rssJson, jsontext); scripting2Suite.writeStaticFile (username, scripting2Suite.data.paths.rssJs, "onGetRss (" + jsontext + ")")}; bundle { //test code local (xmltext = tcp.httpreadurl ("http://scripting.com/rss.xml")); buildRssJson (xmltext, "davewiner")}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.