Changes between Version 4 and Version 5 of UsingFeedsInCode


Ignore:
Timestamp:
May 11, 2006, 6:00:22 PM (15 years ago)
Author:
nick
Comment:

add ColdFusion? stuff

Legend:

Unmodified
Added
Removed
Modified
  • UsingFeedsInCode

    v4 v5  
    99== !ColdFusion ==
    1010
     11An example for grabbing the RDF of a node, and outputting the node's title and OS x and y co-ordinates follows.
     12
     13{{{
     14<cfsilent>
     15    <!--- Grab the RDF of a given Node --->
     16    <!--- Then, parse it, and pull out interesting things --->
     17
     18    <!--- The URL of the RDF to fetch --->
     19    <cfset rdf_url = "http://cotswolds.openguides.org/wiki/wiki.cgi?id=The_Royal_Oak%2C_Ramsden;format=rdf">
     20
     21    <!--- Grab our RDF, and load it into the XML parser --->
     22    <cfhttp url="#rdf_url#" method="get">
     23    <cfif left(cfhttp.statusCode,3) EQ "200" OR left(cfhttp.statusCode,3) EQ "304">
     24        <cfset raw_xml = cfhttp.fileContent>
     25        <cfset xml = XmlParse(raw_xml).xmlRoot>
     26
     27        <!--- Grab the rdf:Description and geo:SpatialThing tags --->
     28        <cfset rdf = "">
     29        <cfset geo_spatial = "">
     30        <cfscript>
     31            for(i = 1; i LTE ArrayLen(xml.XmlChildren); i = i+1) {
     32                if(xml.XmlChildren[i].XmlName EQ "rdf:description") {
     33                    rdf = xml.XmlChildren[i];
     34                }
     35                if(xml.XmlChildren[i].XmlName EQ "geo:SpatialThing") {
     36                    geo_spatial = xml.XmlChildren[i];
     37                }
     38            }
     39        </cfscript>
     40
     41        <!--- Now pull out the title, and OS co-ordinates --->
     42        <!--- For that, we want dc:title and os:x / os:y --->
     43        <cfset dc_title = "">
     44        <cfif rdf NEQ "">
     45            <cfscript>
     46                for(i = 1; i LTE ArrayLen(rdf.XmlChildren); i = i+1) {
     47                    if(rdf.XmlChildren[i].XmlName EQ "dc:title") {
     48                        dc_title = rdf.XmlChildren[i].xmlText;
     49                    }
     50                }
     51            </cfscript>
     52        </cfif>
     53
     54        <cfset os_x = "">
     55        <cfset os_y = "">
     56        <cfif geo_spatial NEQ "">
     57            <cfscript>
     58                for(i = 1; i LTE ArrayLen(geo_spatial.XmlChildren); i = i+1) {
     59                    if(geo_spatial.XmlChildren[i].XmlName EQ "os:x") {
     60                        os_x = geo_spatial.XmlChildren[i].xmlText;
     61                    }
     62                    if(geo_spatial.XmlChildren[i].XmlName EQ "os:y") {
     63                        os_y = geo_spatial.XmlChildren[i].xmlText;
     64                    }
     65                }
     66            </cfscript>
     67        </cfif>
     68    </cfif>
     69</cfsilent>
     70
     71<!--- Now make use of these --->
     72<cfoutput><p>#dc_title# is at OS #os_x#:#os_y#</p></cfoutput>
     73}}}
     74
    1175== Django (Python) ==
    1276
    1377== !JavaScript ==
    1478
    15 Note that the JavaScript will either need to come from the same server as the feed, or be running with the browser granting it extra security rights, otherwise you'll get a security exception when you try to request something off another server.
     79Note that the !JavaScript will either need to come from the same server as the feed, or be running with the browser granting it extra security rights, otherwise you'll get a security exception when you try to request something off another server.
    1680
    1781An example for pulling out titles and modified dates from the recent changes RSS feed, and chucking them into a paragraph with the id "data" follows.