table.cfdump_wddx, table.cfdump_xml, table.cfdump_struct, table.cfdump_array, table.cfdump_query, table.cfdump_cfc, table.cfdump_object, table.cfdump_binary, table.cfdump_udf, table.cfdump_udfbody, table.cfdump_udfarguments {font-size: xx-small; font-family: verdana, arial, helvetica, sans-serif; cell-spacing: 2px;} table.cfdump_wddx th, table.cfdump_xml th, table.cfdump_struct th, table.cfdump_array th, table.cfdump_query th, table.cfdump_cfc th, table.cfdump_object th, table.cfdump_binary th, table.cfdump_udf th, table.cfdump_udfbody th, table.cfdump_udfarguments th {text-align: left; color: white; padding: 5px;} table.cfdump_wddx td, table.cfdump_xml td, table.cfdump_struct td, table.cfdump_array td, table.cfdump_query td, table.cfdump_cfc td, table.cfdump_object td, table.cfdump_binary td, table.cfdump_udf td, table.cfdump_udfbody td, table.cfdump_udfarguments td {padding: 3px; background-color: #ffffff; vertical-align : top;} table.cfdump_wddx {background-color: #000000;} table.cfdump_wddx th.wddx {background-color: #444444;} table.cfdump_xml {background-color: #888888;} table.cfdump_xml th.xml {background-color: #aaaaaa;} table.cfdump_xml td.xml {background-color: #dddddd;} table.cfdump_struct {background-color: #0000cc ;} table.cfdump_struct th.struct {background-color: #4444cc ;} table.cfdump_struct td.struct {background-color: #ccddff;} table.cfdump_array {background-color: #006600 ;} table.cfdump_array th.array {background-color: #009900 ;} table.cfdump_array td.array {background-color: #ccffcc ;} table.cfdump_query {background-color: #884488 ;} table.cfdump_query th.query {background-color: #aa66aa ;} table.cfdump_query td.query {background-color: #ffddff ;} table.cfdump_cfc {background-color: #ff0000;} table.cfdump_cfc th.cfc{background-color: #ff4444;} table.cfdump_cfc td.cfc {background-color: #ffcccc;} table.cfdump_object {background-color : #ff0000;} table.cfdump_object th.object{background-color: #ff4444;} table.cfdump_binary {background-color : #eebb00;} table.cfdump_binary th.binary {background-color: #ffcc44;} table.cfdump_binary td {font-size: x-small;} table.cfdump_udf {background-color: #aa4400;} table.cfdump_udf th.udf {background-color: #cc6600;} table.cfdump_udfarguments {background-color: #dddddd; cell-spacing: 3;} table.cfdump_udfarguments th {background-color: #eeeeee; color: #000000;}
IntroduçãoO RSS primeiro recebeu a nomemclatura RDF Site Summary (Sumário RDF do Site ), depois Rich Site Summary (Sumário Rico do Site) , e em seguida Really Simple Syndication (Distribuidor Realmente Simples), esta última é a forma mais encontrada para definição da sigla. Criado com a finalidade de prover dados/informações a aplicações remotas, foi rapidamente absorvido pelas agências de notícias, e sua importância foi reconhecida com a mesma velocidade, sites como mxstudio, blogs, grupos de discussão, entre outros passaram a adota-lo a partir do momento que foram surgindo os leitores de RSS (Read Feed), deste ponto em diante ele não tem parado de expandir-se e ser divulgado. O leitor de RSS, fazendo uma analogia a vida real, é uma pequena banca de jornais (jornaleiro) que exibe inumeras publicações de categorias distintas, com um breve resumo na capa de cada publicação. E para que isto aconteça basta que seja informado o endereço internet do RSS que deseja colocar na sua banca particular. Alguns exemplos de leitores de RSS: W3C e RSSFoi preciso criar um padrão para que todas as aplicações soubessem onde procurar a informação, e o responsável por esta padronização foi o W3C, que é um consórcio responsável por padronizar as linguagens para todos os navegadores. O W3C o classifica como Resource Description Framework (Estrutura de Descrição do Recurso) . RSS 2.0Agora já sabemos que RSS não é ninguém sorrindo para você e que Atom em sites não tem nada a haver com bomba, então vejamos a estrutura da versão mais usada do RSS. Estrutura do RSS
Com a estrutura completa do RSS obtemos um XML parecido com o script a seguir. <?xml version=“1.0″ encoding=“ISO-8859-1″?>
<rss version=“2.0″> <channel> <title>feed mxstudio</title> <link>http://dns/rss.php</link> <description>Meu site é assim</description> <language>pt-br</language> <copyright>Copyright©MXSTUDIO</copyright> <managingEditor>e-mail (nome)</managingEditor> <webMaster>e-mail (nome) </webMaster> <pubDate>Fri, 24 Jun 2005 02:40:25 GMT</pubDate> <lastBuildDate>Fri, 24 Jun 2005 02:40:25 GMT</lastBuildDate> <rating>http://classificador/rating?id=666</rating> <category domain=“http://classificador/”>666</category> <category>Tecnology</category> <generator>KWrite</generator> <docs>http://dns/</docs> <cloud registerProcedure=“pingMe” port=“númroda porta” path=“/RPC2″ domain=“ip ou host “ protocol=“soap” /> <ttl>20</ttl> <image> <title>alt da imagem</title> <url>url da imagem</url> <link>http://dns/</link> <width>88</width> <height>31</height> </image> <textInput> <title>Buscador </title> <description>dado a ser buscado</description> <name>nome do input do buscador</name> <link>url contida no atributo action do formulário de busca</link> </textInput> <skipHours> <hour>5</hour> <hour>17</hour> </skipHours> <skipDays> <day>Sunday</day> </skipDays> <item> <title>Titulo da matéria [1]</title> <link>link da matéria [1]</link> <guid isPermaLink=“true”> link da matéria [1]</guid> <description>Resumo da matéria [1]</description> <datePosted>Fri, 24 Jun 2005 02:40:25 GMT</datePosted> <comments> Link dos cometários da matéria [1]</comments> <author>e-mail (nome) </author> <source url=“link RSS da matéria”> Titulo do RSS da matéria [1]</source> <enclosure url=“http://dns/1.mp3″ length=“123326320″ type=“audo/mpeg” /> <category domain=“http://classificador/”>1</category> <category>categoria da matéria [1]</category> </item> <item> <title>Titulo da matéria [n]</title> <link>link da matéria [n]</link> <guid isPermaLink=“true”> link da matéria [n]</guid> <description>Resumo da matéria [n]</description> <datePosted>Fri, 24 Jun 2005 02:40:25 GMT</datePosted> <comments> Link dos cometários da matéria [n]</comments> <author>e-mail (nome) </author> <source url=“link RSS da matéria”> Titulo do RSS da matéria [1]</source> <enclosure url=“http://dns/y.mp3″ length=“123326320″ type=“audo/mpeg” /> <category domain=“http://classificador/”>n</category> <category>categoria da matéria [n]</category> </item> </channel> </rss> A Classe para leitura de RSS deve ser bem flexível, para que possa ler qualquer variante deste tipo de estrutura, e não retorne erros. A descrição da classe foi feita de forma simplificada. Então vejamos esta classe. <!— Aqui inciamos um o componente ou classe —>
<cfcomponent displayname=”Leitor RSS”> <!— declaramos os atributos do componente, ou melhor, como estamos usando a tag cfproperty, criamos as propriedades do componente, isto significa que futuramente poderemos transformar esta classe em um tipo de dado, um exemplo de tipo de dado é o array, ou declarar dados complexos. Quando iniciamos um objeto usando um componente com esta tag em seu escopo esses atributos estão sujeitos as regras de herança. —> <cfproperty name=”url” type=”string” hint=”Endereço do RSS” /> <cfproperty name=”xmldoc” hint=”RSS no formato xml.” /> <cfproperty name=”title” type=”string” /> <cfproperty name=”link” type=”string” /> <cfproperty name=”description” type=”string” /> <cfproperty name=”pubDate” type=”string” /> <cfproperty name=”lastBuildDate” type=”string” /> <cfproperty name=”category” type=”struct” /> <cfproperty name=”image” type=”struct” /> <cfproperty name=”item” type=”query” /> <cfproperty name=”language” type=”string” /> <cfproperty name=”copyright” type=”string” /> <cfproperty name=”managingEditor” type=”string” /> <cfproperty name=”ttl” type=”string” /> <cfproperty name=”webMaster” type=”string” /> <cfproperty name=”generator” type=”string” /> <cfproperty name=”docs” type=”string” /> <cfproperty name=”could” type=”struct” /> <cfproperty name=”textInput” type=”struct” /> <cfproperty name=”skipHours” type=”array” /> <cfproperty name=”skipDays” type=”array” /> <cfproperty name=”rating” type=”string” /> <cffunction name=”setUrl” access=”public” output=”false” returntype=”string” <cffunction name=”getUrl” access=”private” output=”false” returntype=”string” <cffunction name=”setXMLdoc” access=”private” output=”false” <cffunction name=”getXMLdoc” access=”private” output=”false” returntype=”any” <cffunction name=”setTitle” access=”private” output=”false” <cffunction name=”getTitle” access=”private” output=”false” returntype=”string” <cffunction name=”setLink” access=”private” output=”false” <cffunction name=”getLink” access=”private” output=”false” returntype=”string” <cffunction name=”setDescription” access=”private” output=”false” <cffunction name=”getDescription” access=”private” output=”false” returntype=”string” <cffunction name=”setPubDate” access=”private” output=”false” <cffunction name=”getPubDate” access=”private” output=”false” returntype=”string” <cffunction name=”setLastBuildDate” access=”private” output=”false” <cffunction name=”getLastBuildDate” access=”private” output=”false” returntype=”string” <cffunction name=”searchCategory” returntype=”struct” access=”private” output=”false”> <cffunction name=”setCategory” access=”private” output=”false” <cffunction name=”getCategory” access=”private” output=”false” returntype=”struct” <cffunction name=”setImage” access=”private” output=”false” <cffunction name=”getImage” access=”private” output=”false” returntype=”struct” <cffunction name=”setItens” access=”private” output=”false” //Existem quatro tipos de tags em item, que são: instance.item = QueryNew(temp); } <cffunction name=”getItens” access=”private” output=”false” returntype=”query” if(IsDefined(“instance.item”)) <cffunction name=”setLanguage” access=”private” output=”false” <cffunction name=”getLanguage” access=”private” output=”false” returntype=”string” <cffunction name=”setCopyright” access=”private” output=”false” <cffunction name=”getCopyright” access=”private” output=”false” returntype=”string” <cffunction name=”setManagingEditor” access=”private” output=”false” <cffunction name=”getManagingEditor” access=”private” output=”false” returntype=”string” <cffunction name=”setTtl” access=”private” output=”false” <cffunction name=”getTtl” access=”private” output=”false” returntype=”string” <cffunction name=”setWebMaster” access=”private” output=”false” <cffunction name=”getWebMaster” access=”private” output=”false” returntype=”string” <cffunction name=”setGenerator” access=”private” output=”false” <cffunction name=”getGenerator” access=”private” output=”false” returntype=”string” <cffunction name=”setDocs” access=”private” output=”false” <cffunction name=”getDocs” access=”private” output=”false” returntype=”string” <cffunction name=”setCould” access=”private” output=”false” <cffunction name=”getCould” access=”private” output=”false” returntype=”struct” <cffunction name=”setTextInput” access=”private” output=”false” <cffunction name=”getTextInput” access=”private” output=”false” returntype=”struct” <cffunction name=”setSkipHours” access=”private” output=”false” <cffunction name=”getSkipHours” access=”private” output=”false” returntype=”array” <cffunction name=”setSkipDays” access=”private” output=”false” <cffunction name=”getSkipDays” access=”private” output=”false” returntype=”array” <cffunction name=”setRating” access=”private” output=”false” <cffunction name=”getRating” access=”private” output=”false” returntype=”string” <cffunction access=”public” name=”init” output=”false” <cffunction name=”getRss” access=”public” output=”false” returntype=”struct” <cffunction name=”get” access=”public” output=”false” returntype=”any” metodos = metodos&”,Description,Category,Language,Copyright,ManagingEditor,Ttl”; //verifca a presença de parametros <cffunction name=”XMLSearchXmlText” access=”private” returntype=”string”> <cffunction name=”searchItem” access=”public” returntype=”query”> </cfcomponent> Agora será feita uma sequência de dumps do objeto RSS para saber o que ele nos retorna, e com isso veremos também como funciona a interface do dump que é bastante elaborada. Instanciando um objeto RSS <cfset rss=CreateObject(“component”,”rss.rss”) />
<cfset rss.init(“http://localhost:8300/rss/mxstudio.xml”) /> <cfdump var=”#rss#”> <cfset rss = “nothing” /> Estrutura do objeto RSS apenas instanciado
Instanciando um objeto RSS e reutilizando o objeto para ser usado como variável de acesso direto. <cfset rss=CreateObject(“component”,”rss.rss”) />
<cfset rss.init(“http://localhost:8300/rss/mxstudio.xml”) /> <cfset rss['dados'] = rss.getRss() /> <cfdump var=”#rss#”> <cfset rss = “nothing” /> Nova estrutura do objeto RSS
Executando uma consulta nas notícias do RSS <cfset rss=CreateObject(“component”,”rss.rss”) />
<cfset rss.init(“http://localhost:8300/rss/mxstudio.xml”) /> <cfdump var=”#rss.searchItem(‘title’,'author’,'e-mail (nome)’)#” /> <cfset rss = “nothing” /> Retorno da consulta
Instanciando um objeto RSS e exibindo uma informação do cabeçalho do RSS <cfset rss=CreateObject(“component”,”rss.rss”) />
<cfset rss.init(“http://localhost:8300/rss/mxstudio.xml”) /> <cfoutput>#rss.get(“title”)#</cfoutput> <cfset rss = “nothing” /> O retorno desta solicitação é uma variável de estrutura simples feed mxstudio
Instanciando um objeto RSS e exibindo multiplas informações do cabeçalho do RSS <cfset rss=CreateObject(“component”,”rss.rss”) />
<cfset rss.init(“http://localhost:8300/rss/mxstudio.xml”) /> <cfdump var=”#rss.get(‘title’,'url’)#” /> <cfset rss = “nothing” /> O retorno desta solicitação é uma variável de estrutura complexa (tipo estrutura)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Últimos Comentários