Skip to main content
Participant
September 30, 2008
Answered

parse rss issue

  • September 30, 2008
  • 4 replies
  • 410 views
I've been trying to parse this rss feed
http://www.economicnews.ca/cepnews/wire/rss/custom?u=camagazine&p=39d7g7d9

Here is the code I'm using:
<!--- Retrieve the RSS document --->
<cfhttp url=" http://www.economicnews.ca/cepnews/wire/rss/custom?u=camagazine&p=39d7g7d9" method="get">
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">
</cfhttp>

<!--- Validation flag --->
<cfset XMLVALIDATION = true>

<cftry>
<!--- Create the XML object --->
<cfset objRSS = xmlParse(cfhttp.filecontent)>

<cfcatch type="any">
<!--- If the document retrieved in the CFHTTP
is not valid set the validation flag to false. --->
<cfset XMLVALIDATION = false>
</cfcatch>
</cftry>

<cfif XMLVALIDATION>
<!--- If the validation flag is true continue parsing --->

<!--- Set the XML Root --->
<cfset XMLRoot = objRSS.XmlRoot>

<!--- Retrieve the document META data --->
<cfset doc_title = XMLRoot.channel.title.xmltext>
<cfset doc_link = XMLRoot.channel.link.xmltext>
<cfset doc_description = XMLRoot.channel.description.xmltext>
<cfset doc_content = XMLRoot.channel.content.xmltext>

<!--- Output the meta data in the browser --->
<!-- <cfoutput>
<b>Title</b>: #doc_title#<br/>
<b>Link</b>: #doc_link#<br/>
<b>Description</b>: #doc_description#<br/><br/>
</cfoutput> -->

<!--- Retrieve the number of items in the channel --->
<cfset Item_Length = arraylen(XMLRoot.channel.item)>

<!--- Loop through all the items --->
<cfloop index="itms" from="1" to="2">
<!--- Retrieve the current Item in the loop --->
<cfset tmp_Item = XMLRoot.channel.item[itms]>

<!--- Retrieve the item data --->
<cfset item_title = tmp_item.title.xmltext>
<cfset item_link = tmp_item.link.xmltext>
<cfset item_description = tmp_item.description.xmltext>
<cfset item_content = tmp_item.content.xmltext>


<!--- Output the items in the browser --->
<cfoutput>
<a href="#item_link#" target="_blank"><strong>#item_title#</strong></a><br/>
#item_description#<br/><br/><br />
#item_content#
</cfoutput>
</cfloop>

<cfelse>
<!--- If the validation flag is false display error --->
Invalid XML/RSS object!
</cfif>

But it gives me the following error:
Element CHANNEL.CONTENT.XMLTEXT is undefined in XMLROOT.

The error occurred in E:\inetpub\wwwroot\cica\shane_upload_folder\rss_parse.cfm: line 31

29 : <cfset doc_link = XMLRoot.channel.link.xmltext>
30 : <cfset doc_description = XMLRoot.channel.description.xmltext>
31 : <cfset doc_content = XMLRoot.channel.content.xmltext>


I've checked and re-checked, I've done dumps and the content is there, so I'm not sure what the heck it doesn't like. Thoughts anyone?
This topic has been closed for replies.
Correct answer Newsgroup_User
SirPainkiller wrote:
> Ohhh I see. Ok so if we look under ITEM there is title, link, description, content:encoded, etc.. So now the question is how to I reference the content:encoded that is under item??
>
> Shane

When accessing that type of RSS feed you need to use array notation
rather then dot notation to get at the elements.

I.E.

<cfset doc_content =
XMLRoot['channel']['item']['content:encoded']['xmltext']>

4 replies

Participant
September 30, 2008
Awsome, that worked. Thanks guys I really appreciate it.

Shane
Newsgroup_UserCorrect answer
Inspiring
September 30, 2008
SirPainkiller wrote:
> Ohhh I see. Ok so if we look under ITEM there is title, link, description, content:encoded, etc.. So now the question is how to I reference the content:encoded that is under item??
>
> Shane

When accessing that type of RSS feed you need to use array notation
rather then dot notation to get at the elements.

I.E.

<cfset doc_content =
XMLRoot['channel']['item']['content:encoded']['xmltext']>
Participant
September 30, 2008
Ohhh I see. Ok so if we look under ITEM there is title, link, description, content:encoded, etc.. So now the question is how to I reference the content:encoded that is under item??

Shane
Inspiring
September 30, 2008
in my dump of that rss feed CHANNEL does NOT have CONTENT
(it only has XMLTEXT, IMAGE, TITLE, LINK, DESCRIPTION, COPYRIGHT and ITEMs)

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/