Skip to main content
Inspiring
May 20, 2010
Question

creating a coldfusion webservice to return xml problem

  • May 20, 2010
  • 1 reply
  • 1401 views

Hi I am creating a coldfsion webservice that is to be used by other platforms ( asp etc). In my webservice I have a method that I want to return data as XML which can then be read easily by these different platforms. At the moment I have something like this....

<cffunction name="getBlogs" hint="I search the live blogs" access="remote" returntype="xml">
        <cfargument name="limit" required="No" default="" type="any">
        <cfargument name="blogCategoryTypeName" required="No" default="Web analytics" type="any">
        <cfset var qrySearch = "">
        <cfset var strXML = "">
        <cfquery name="qrySearch" datasource="#variables.dsn#">
            select    
                blogsLive.blogId
                , blogsLive.blogHeadline
                , blogsLive.blogSummary                    
            from        
                blogs
            where
                blogslive.blogStatusId = 2
        </cfquery>
              
       <cfsetting enablecfoutputonly="true" />
        <cfprocessingdirective suppresswhitespace="yes">
        <cfxml variable="objXML">       
        <cfoutput>
          <blogs>
              <cfloop array="#results#" index="b">
              <blog id="#b['blogId']#">
                <headline>#XMLFormat(b['blogHeadline'])#</headline>
                <summary>#XMLFormat(b['blogSummary'])#</summary>
              </blog>
            </cfloop>         
          </blogs>
        </cfoutput>               
        </cfxml>
        <cfset strXML = #ToString(objXML)#>
        <cfset strXML = #replace(strXML,"<?xml version=""1.0"" encoding=""UTF-8""?>","")#>
        </cfprocessingdirective>    
                                               
        <cfreturn strXML>
   
    </cffunction>

The problem I am having is that when calling this webservice via classic ASP for example it sees the xml as a string and hence it quite difficult to manipulate. I would like to return the data like the following example:

http://api.getclicky.com/api/stats/4?site_id=32020&sitekey=2e05fe2778b6&type=visitors,countries,searches

How can i get the webservice to return data like the link above? So for example if i call mty webservice like link above i get the same type of result?

Any help much appreciated

This topic has been closed for replies.

1 reply

Inspiring
May 20, 2010

I've had similar issues.  I've been asked to write web services for asp.net apps and basically, if you include the opening xml tag, asp can't consume it.  I handled my own problem by including an argument that determined whether to return the data with the xml tag or without.