How can you format the datePub XML? You can not use DateFormat(). How can you select out only XML content by the datePub? The data I am using includes sports scores over several days, but I only want to post score for today.
Hello everyone, I wanted to write a tutorial
explaining how to use XML/RSS feeds you see all over the place these days
(specially on Blogs such as BlogColony.Com).
Let's begin:
First we need to define where the XML/RSS feed is located on the web, this is
the direct URL to it:
<cfscript>
URLToPull = "http://archive.easycfm.com/syndication/mostviewed.cfm";
</cfscript>
The next step is to actually do a CFHTTP to
the location you specified, this is how you get the values of the XML/RSS from
the site you want (in this case, the 5
most viewed EasyCFM.Com Tutorials):
<cfhttp url="#URLToPull#"
method="GET"
timeout="15">
</cfhttp>
Here, first let's define a variable called
XMLContent and assign the returned value of CFHTTP to it, next let's trim() it
to ensure that the XML is correctly parsed by the line below that.
<cfscript>
XMLContent = trim(cfhttp.filecontent);
XMLContent = XMLParse(XMLContent);
</cfscript>
Now, let's actually output the information about
the feed, in this case the site logo, title and description:
<cfoutput>
Feed provided by:<BR>
<a
href="#XMLContent.rss.channel.image.link.xmlText#">
<img
src="#XMLContent.rss.channel.image.url.xmlText#" alt="#XMLContent.rss.channel.image.title.xmlText#"
border="0">
</a><br>
#XMLContent.rss.channel.title.xmlText#<BR>
#XMLContent.rss.channel.description.xmlText#<BR><BR>
</cfoutput>
Now we will use the array value "XMLContent.rss.channel.item"
which will let us know how many records we want to process and display:
<cfloop from="1" to="#ArrayLen(XMLContent.rss.channel.item)#"
index="idx">
<hr>
<cfoutput>
<a href="#XMLContent.rss.channel.item[idx].link.xmlText#">#XMLContent.rss.channel.item[idx].title.xmlText#</a><BR>
#ParagraphFormat(ReplaceNoCase(XMLContent.rss.channel.item[idx].description.xmlText,
"<", "<", "ALL"))#
Author: #XMLContent.rss.channel.item[idx].author.xmlText#<BR>
Date: #XMLContent.rss.channel.item[idx].pubDate.xmlText#
</cfoutput>
</cfloop>
Last, let's display the actual copyright notice
that the feed itself returns:
<HR>
<cfoutput><div align="center">#XMLContent.rss.channel.copyright.xmlText#</div></cfoutput>
And that's pretty much it...
Remember that you can also do this if you are
stuck along the way:
<cfdump var="#XMLContent#">
That will dump out the XML file and that will allow you to see what you're
doing.
You can go entering data in the CFDUMP tag as follows:
<cfdump var="#XMLContent#">
- This till show you the main XML document.
<cfdump var="#XMLContent.rss#">
- This will take you into the RSS branch
<cfdump var="#XMLContent.rss.XMLChildren[1]#">
- this will take you into the first child branch of the rss section.
and so forth, you can work your way down to each individual item in the feed.
Questions? Comments? Let me know...
How can you format the datePub XML? You can not use DateFormat(). How can you select out only XML content by the datePub? The data I am using includes sports scores over several days, but I only want to post score for today.
Love the tutorial - works great! However, I'm attempting to display the contents of an Eventbrite RSS feed. They've placed the main content inside of this tag...
I also get this error
"An error occured while Parsing an XML document.
Content is not allowed in prolog.
I also get the same error from time to time. Sometimes it works and sometimes it doesn't.
Also I was unable to use some rss such as from google.
"An error occured while Parsing an XML document.
Content is not allowed in prolog.
The error occurred in /var/chroot/home/content/n/s/h/xxx/html/trial.cfm: line 90
88 :
When trying your tutorial on CFMX 7 enterprise I am getting the following error?
Any ideas on how to get around this ?
An error occured while Parsing an XML document.
Content is not allowed in prolog.
The error occurred in F:\Websites\Intranet\testpages\xmlrss.cfm: line 16
14 :
Is there a way to avoid that kind of error from the rss provider?
Pablo,
The tutorial works fine for the test data in the tutorial, but the feed I am trying to process and display has an rdf section rather than an rss section. Changing rss to rdf does not help even though the sections appear to line up otherwise. The
hi,im new to coldfusion and i want to know how can i make use of the contents of other sites to be in my site.for example news items from other sites and i want to syndicate such news to be available in my site.thanks in advance
Did you have a question Eugene?
Your CDATA must be INSIDE the