Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

Unqualified XML's and cfheader

I've been playing around with creating an XML file this morning from a plain .cfm page and came across an annoyance. Now I've done this loads but this morning I was creating my own Ajax functions which meant the cfm page had to return a fully qualfied as XML which was passed into Javascripts XML parser, but Js was passing an error. The test code was simple

[xml.cfm]

view plain print about
1<cfheader name="Content-Type" value="text/xml">
2<?xml version="1.0" encoding="UTF-8"?>
3<root>
4 <node>
5 <child>1</child>
6 </node>
7<root>

The problem was CFHEADER adds a couple of blank lines to the top of the page meaning that the page did not pass as XML. Well thanks to Rob Wilkerson on CF-Talk the anser was obvious simple - use CFCONTENT

view plain print about
1<cfcontent type="text/xml" reset="Yes" />
2<?xml version="1.0" encoding="UTF-8"?>
3<root>
4 <node>
5 <child>1</child>
6 </node>
7<root>

I did try a few other ways of surpressing the white space usin a variety of methods but nothing came close.

Comments Comments (1) | Print Print | Send Send | 3632 Views

If you like what you see on the website and/or this post has helped you out in some way please consider donating to help keep me in beer vodka. The donations are made through Paypal, which accepts almost any credit card or eCheck.

(Comment Moderation is enabled. Your comment will not appear until approved.)
this post helped me get out of a jam when transposing ajax examples from PHP to ColdFusion. thanks!
BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .