Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error while Parsing an XML document (Coldfusion)

Posted on 2012-03-09
7
Medium Priority
?
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 37704385
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_
ID: 37704389
<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
ID: 37707582
I will try theses thanks!!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Author Comment

by:RickEpnet
ID: 37708076
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_
ID: 37708104
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
ID: 37708109
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 2000 total points
ID: 37708271
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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