• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

parse rss issue

New Here ,
Sep 30, 2008 Sep 30, 2008

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

358

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 30, 2008 Sep 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']>

Votes

Translate

Translate
LEGEND ,
Sep 30, 2008 Sep 30, 2008

Copy link to clipboard

Copied

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/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2008 Sep 30, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 30, 2008 Sep 30, 2008

Copy link to clipboard

Copied

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']>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2008 Sep 30, 2008

Copy link to clipboard

Copied

LATEST
Awsome, that worked. Thanks guys I really appreciate it.

Shane

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation