Ok guys - rookie move on my part.  

Using the conditional "IsDefined" works perfectly in stopping the XML from 
parsing when no news results are returned.  Here's the complete working code:

<cfoutput>
<form action="#script_name#" method="post">
<input type="text" name="search_term" size="30" /> <input type="submit" 
value="Display Yahoo News Articles" />
</form><br />
<br />

</cfoutput>

<cfparam name="RSS_URL" default="">
<cfparam name="search_term" default="">

<cfif search_term neq "">
        <cfset search_term = #Replace(search_term, " ", "+", "All")#>
</cfif>


<cfif search_term neq "">


        <cfset RSS_URL = 
"http://news.search.yahoo.com/news/rss?p=#search_term#&ei=UTF-8&fl=0&x=wrt";>
        
        <cfhttp throwonerror="yes" url="#rss_url#" method="get" 
timeout="10"></cfhttp>

        <!--- <cfoutput>#cfhttp.filecontent#</cfoutput> --->


        
        <cfif cfhttp.filecontent does not contain "gif false">
        
                <cfset xmlDoc = XMLParse(cfhttp.filecontent)> 
                
                <!--- <cfdump var="#xmldoc#"> --->
                
                <cfif IsDefined("xmlDoc.RSS.CHANNEL.ITEM")>
                
                <cfoutput> 
                #xmlDoc.rss.channel.title.xmlText#<br> 
                <a 
href="#xmlDoc.rss.channel.link.xmlText#">#xmlDoc.rss.channel.link.xmlText#</a><br>
                #xmlDoc.rss.channel.lastBuildDate.xmlText#<br> 
                <hr>
                
                <cfloop from="1" to="#ArrayLen(xmlDoc.rss.channel.item)#" 
index="i"> 
                <p> 
                <a 
href="#xmlDoc.rss.channel.item[i].link.xmlText#">#xmlDoc.rss.channel.item[i].title.xmlText#</a><br
 /> 
                #xmlDoc.rss.channel.item[i].description.xmlText#<br /> 
                </p> 
                </cfloop>               
                </cfoutput>
                
                <cfelse>
                        
                        <cfoutput>
                        No current news stories matched your search criteria 
"<strong>#search_term#</strong>".
                        </cfoutput>
                
                </cfif>
                
        </cfif>

</cfif>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227017
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to