EasyCFM.COM ColdFusion Forums / Coding Help! / Yahoo RSS News Feed Help

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Yahoo RSS News Feed Help

remove book mark from this topic Printer-friendly Version  send this discussion to a friend  new posts last

area215
03-05-2004 @ 9:18 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 15
Joined: Feb 2004

I was wondering if anyone could help me with this?

I want to use yahoos news feeds on my site.
When I put a direct URL link to an XML file on my computers CFMX Server It works.

Example:
<CFHTTP URL="http://localhost:8500/news/health.xml" METHOD="get" RESOLVEURL="no"/>

Now when I direct the URL link to Yahoos feed it comes up with an error saying that a Document root element is missing!

Can anyone help me with this.

Here Is my code:

<CFHTTP URL="http://rss.news.yahoo.com/rss/health" METHOD="get" RESOLVEURL="no"/>

<CFSCRIPT>
  objRSS = trim(cfhttp.filecontent);
  objRSS = XMLParse(objRSS);
</CFSCRIPT>

<CFSET XMLRoot = objRSS.XmlRoot >
<CFSET News_Length = arraylen(XMLRoot.channel.item) >

<CFLOOP index="i" from="1" to="#News_Length#" >
  <CFSET item_title = XMLRoot.channel.item.title.xmltext >
  <CFSET item_link = XMLRoot.channel.item.link.xmltext >
  <CFSET item_pubDate = XMLRoot.channel.item.pubDate.xmltext >
  <CFSET item_description = XMLRoot.channel.item.description.xmltext >
  <CFOUTPUT>
  <STRONG>#item_title#</STRONG><br/>
          #item_pubDate#<br/>
<a href="#item_link#">#item_description#</a><br/>
    <br/>
  </CFOUTPUT>
</CFLOOP>


I even tried the tutorials on here and I am still getting the same error.



Thanks,
Area215

CJ
03-05-2004 @ 10:00 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

well, first step in debugging is to isolate the error.

since you're getting the error using the XMLParse() fucntion on a value, let's check the value.

after your cfhttp call, do this:

<cfdump var="#cfhttp#">
<cfabort>

i bet you'll see the connection failed (which is why the XMLParse() function is failing).

as far as *why* the connection failed?  dunno.  fact of the matter is that i'm getting the same thing.  

looking into it.  if i figure out the problem, I'll post back.



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

CJ
03-05-2004 @ 10:11 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

almost certainly a firewall issue.  are you behind a firewall?

firewalls can wreak havoc with cfhttp

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

CJ
03-05-2004 @ 10:26 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

ok...here we go:

(i took the liberty of 'cleaning up' some of the code...i'll comment where i can)


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title>Untitled</title>
     <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
</head>

<body>


<!--- a CFMX 'fix' for consuming web svcs from behind proxy --->
<!--- courtesy of http://blog.daemon.com.au/archives/000047.html --->

<cfscript>
     obj = CreateObject("java", "java.lang.System");
     obj.setProperty("http.proxyHost", "xxx.xxx.xxx.xxx"); // your proxy server IP (or address)
     obj.setProperty("http.proxyPort", "xxxx"); // your proxy server port
</cfscript>

<cfhttp
     url="http://rss.news.yahoo.com/rss/health"
     method="get"
>

<cfscript>
  objRSS = trim(cfhttp.filecontent);
  objRSS = XMLParse(objRSS);
</cfscript>

<!---
here, i mostly just removed all of the assignments you had.  rationale being there was no reason to create a variable assignment with each iteration of the loop.  that's just extra resources at runtime and extra lines of code.  if you're not planning to re-use those vars, they're really unnecessary.

also, i moved the <cfoutput> blocks to *outside* of the <cfloop>.  i have a tutorial on 'best practices' in coding that goes into detail as to why this is MUCH better

oh, and the only reason i changed the loop index from 'i' to 'newsitem' is that the forums see [ i ] as an italics indicator Smile  
--->

<cfoutput>
     <cfloop index="newsitem" from="1" to="#arraylen(objRSS.XMLRoot.channel.item)#">
          <strong>#objRSS.XMLRoot.channel.item[newsitem].title.xmltext#</strong><br/>
          #objRSS.XMLRoot.channel.item[newsitem].pubDate.xmltext#<br/>
          <a href="#objRSS.XMLRoot.channel.item[newsitem].link.xmltext#">
               #objRSS.XMLRoot.channel.item[newsitem].description.xmltext#
          </a><br/>
          <br/>
     </cfloop>
</cfoutput>

</body>
</html>


-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

This message was edited by CJ on 3-5-04 @ 10:41 AM

area215
03-05-2004 @ 11:55 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 15
Joined: Feb 2004

I tried the code above and am still getting this error!  Did the code work for you?

Document root element is missing.  
Document root element is missing.  
  
The error occurred in C:\CFusionMX\wwwroot\News\TMP95vqgu44fw.cfm: line 13

11 : <CFSCRIPT>
12 :   objRSS = trim(cfhttp.filecontent);
13 :   objRSS = XMLParse(objRSS);
14 : </CFSCRIPT>
15 :


Oh, sorry for seeming dumb but how do I figure out what my http.proxyHost and http.proxyPort are.

I am just using the Cold Server on my computer for Development.  And I am using NetZero to connect to the internet.  Hope this helps a bit.

Thanks
Area215

Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.