Skip to main content
Known Participant
November 3, 2012
Question

xmlParse fails, CFHTTP issue?

  • November 3, 2012
  • 3 replies
  • 7219 views

Hello,

I am attempting to parse xml from a web service. i am getting a "content not allowed in prolog" error which i've debugged before. What confuses me this time is the data returned by calling the xml in a browser is significantly different than the data shown by doing a CFDump. For example, if i place the url in a web broswer, i receive this (i'm only showing the first few lines):

<ArrayOfSpecial xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Some.File">

<Special>

     <Id xmlns="http://schemas.datacontract.org/2004/07/Ski">300033</Id>

     <CarRentalSpecial i:nil="true"/>

     <Description>Some content</Description>

     <Destination>Aspen</Destination>

     <DestinationId>3</DestinationId>

     <EquipmentRentalSpecial i:nil="true"/>

     <ExpirationDate>2012-11-15T00:00:00</ExpirationDate>

When calling the same service via cfhttp and doing a cfdump, i get (again, i'm only showing the first few lines returned, as is):

[{"Name":"Aspen 7 night stay.","DestinationId":3,"Destination":"Aspen ","Description":"Buy 5 Nights, Get Two Nights Free + 1 Day Free Skiing!","MaximumSavings":2318.0,"MinimumPrice":6505.0,"NumberOfNights":7,"Occupancy":2,"Featured":true,"FeaturedPosition":0,"ResortPosition":2,"FeaturedFrequency":50,"RequiresGroup":false,"LodgeSpecial":

Why is the returned data different? Am i not calling the service properly? My browser seems to have no issue parsing this, but ColdFusion (version 10) can't seem to deal with this.

    This topic has been closed for replies.

    3 replies

    BKBK
    Community Expert
    Community Expert
    November 4, 2012

    ggantzer2 wrote:

    I am attempting to parse xml from a web service. i am getting a "content not allowed in prolog" error

    Just remember something. Consider the following:

    <cfsavecontent variable="xmlDoc">   <?xml version="1.0" encoding="UTF-8" ?>

    <bookstore>

    <book category="web" cover="paperback">

    <title lang="en">Learning XML</title>

    <author>Erik T. Ray</author><

    year>2003</year>

    <price>39.95</price>

    </book>

    </bookstore>

    <cfsavecontent>

    I have deliberately put a space just before the XML declaration. When you attempt to parse xmlDoc as an XML object, you might get the error "content not allowed in prolog". The "content" in this case is the preceding space. One way to cure this would therefore be to apply xmlDoc=trim(xmlDoc) before parsing.

    ggantzer2Author
    Known Participant
    November 4, 2012

    i think this is actually related to the content-type. I don't think CF is understanding that its xml. How would i tell it to treat it as xml?

    Inspiring
    November 4, 2012

    i think this is actually related to the content-type. I don't think CF is understanding that its xml. How would i tell it to treat it as xml?

    Did you see my reply to you from y/day?

    --

    Adam

    BKBK
    Community Expert
    Community Expert
    November 4, 2012

    You give a lot of different information here. It makes it difficult to see the wood for the trees. Could you show us the code that defines the XML, and the code that parses it. That is essentially where the error occurs, isn't it?

    Inspiring
    November 3, 2012

    Read the docs for the web service. At a guess, it seems to me that it returns differently formatted data depending on the "accepts" header of the incoming request.  This is standard/common practice with RESTful web services.  So your web browser is sending a different value for the "accepts" header than the <cfhttp> call. It'll most likely be explained in the docs for the web service.

    --

    Adam

    ggantzer2Author
    Known Participant
    November 4, 2012

    i think the issue may be that the url i am calling in the cfhttp has no extension, so ColdFusion doesnt understand it as xml. if i added a <cfhttpparam type="HEADER" name="Content-Type", would this work? What would i set the value to?