I rewrote an application of mine using XML and web services. However, when I 
uploaded it to my hosting server I learned that CFCONTENT was disabled. This 
was a problem because I knew of no other method for setting the mime type to 
XML. I found several articles on serving image content via CFMX, without using 
CFCONTENT. Of those I found, "Using ColdFusion to Write Out Binary Data" by 
Christian Cantrell, was the best. However, it took a bit of fiddling to make it 
work with XML. Below is my solution.

If this is of any use to you great.
If you have a better method of serving XML without using CFCONTENT please share 
it.

<cfscript>
        function stripNonTag(sInput){
                sInput = reReplace( sInput, ">[\s\r\n]*<", "><", "all" );
                return sInput;
        }

        function stringToByteArray(s, compressFlag){
                var byteArray = ArrayNew(1);
                var sLen = 0;
                var i = 1;
                var byteValue = 0;              
                
                if(compressFlag)
                        s = stripNonTag(s);
                        
                sLen = Len(s);
                
                for(i=1; i LTE sLen; i = i + 1){
                        byteValue = Asc(Mid(s, i, 1));
                        ArrayAppend(byteArray, byteValue);
                }
                
                return byteArray;
        }

        function serveXML(xmlString, compressFlag){
                var xmlBytes = stringToByteArray(xmlString, compressFlag);

            context = getPageContext();
            context.setFlushOutput(false);
            response = context.getResponse().getResponse();
            out = response.getOutputStream();
                
            response.setContentType("text/xml; charset=utf-8");
            response.setContentLength(ArrayLen(xmlBytes));
            out.write(xmlBytes);
            out.flush();
            out.close();
        }
</cfscript>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:257384
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to