Solved

Error while Parsing an XML document (Coldfusion)

Posted on 2012-03-09
7
466 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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 500 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML SQL 8 32
XML Document XPath with Namespaces 3 40
Coldfusion can Create a folder but unable to delete as the folder has readonly attribute. 6 47
C# XML Get Values 4 52
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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