Solved

Error while Parsing an XML document (Coldfusion)

Posted on 2012-03-09
7
456 Views
Last Modified: 2012-03-19
CF8 Windows 2003 IIS

I am getting this error
Content is not allowed in prolog

From this code.
 <cfhttp url="http://www.sbnation.com/ncaa-football/teams/pittsburgh-panthers/rss" method="get">
     <cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
 </cfhttp>
      <cfset objRSS = xmlParse(cfhttp.filecontent)>
    <CFDUMP var="#objRSS#">

I cannot figure it out please help.
0
Comment
Question by:RickEpnet
  • 4
  • 3
7 Comments
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Content is not allowed in prolog

The headers aren't quite right, so the call is actually failing. If you dump the cfhttp content the result is actually "Connection Failure" instead of valid xml. That's why your xmlParse isn't working.  By default CFHTTP doesn't throw an error if something goes wrong. So you should always check the status code to verify the call succeeded.  


The correct headers from: Workaround for CFHTTP and Compressed HTTP Response from IIS


<cfhttp url="http://www.sbnation.com/ncaa-football/teams/pittsburgh-panthers/rss"
      method="get">
      <cfhttpparam type="header" name="Accept-Encoding" value="*" />
      <cfhttpparam type="Header" name="TE" value="deflate;q=0">
</cfhttp>
<cfif cfhttp.statusCode eq "200 OK">
      <cfset objRSS = xmlParse(cfhttp.filecontent)>
      success... do something with results
<cfelse>
      call failed. do error handling ...
    <cfdump var="#cfhttp#" label="Debug results">
</cfif>
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
<cfif cfhttp.statusCode eq "200 OK">

fyi - status code isn't 100% bullet proof. Sometimes you get a 200 OK for failed pages too. But it's better than not checking at all.

Edit: You could also set throwonerror="true" and wrap everything in a try/catch. It may be a little more expensive, but is probably more robust than checking the status.

<cftry>
      <cfhttp url="http://www.sbnation.com/ncaa-football/teams/pittsburgh-panthers/rss"
            method="get" throwonerror="true">
            .... headers
      </cfhttp>
      <cfset objRSS = xmlParse(cfhttp.filecontent)>
      success... do something with results
      <cfcatch>
            failed .. do error handling here
      </cfcatch>
</cftry>
0
 
LVL 14

Author Comment

by:RickEpnet
Comment Utility
I will try theses thanks!!
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Author Comment

by:RickEpnet
Comment Utility
Although your second post works as far as the error handling. I think there should be a way to phrase the sbnation rss feeds. Any ideas.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
I think there should be a way to phrase the sbnation rss feeds.

Sorry I don't understand the question.  The 1st post does parse the feed correctly. Was there some other issue?
0
 
LVL 14

Author Comment

by:RickEpnet
Comment Utility
I still get an error when I run the first Post. It is showing connection failure could it be that SBnation is blocking the connect from the web server?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
Possibly or maybe a connection problem on your end? It works fine for me. I retried it just now to confirm and the code still successfully retrieves and parses the feed. So it's definitely some sort of connection related problem.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now