?
Solved

Error while Parsing an XML document (Coldfusion)

Posted on 2012-03-09
7
Medium Priority
?
468 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
Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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