after playing with it a little, i find more success using the following:
It's a type of query in Microsoft SQL Server that will
return formatted XML data to you as a string basically. There are a host of
options for FOR XML queries and I'm not going to get into that at all for this
tutorial. Google 'FOR XML RAW AUTO EXPLICIT' for some good information.
Now, this would be much easier if Cold Fusion would allow you to refer to
columns as an ordinal, but it doesn't as far as I know. You can acquire the
column name and use that to get your column though. That would be great except
that FOR XML queries use a generated column name which always contains a '-' and
Cold Fusion doesn't like '-' characters in it's column names.
What to do, oh what to do.
Fear not! Query of Queries to the rescue. It's fairly self explanitory, but
i'll explain a little. First we execute a FOR XML query to get a stream of XML
data. Then we do a select from that where 0=1 so we don't get any results. In
queries using UNION ALL the first result set will have the column names so we
rename the column (there's only one) to 'xml' (can be anything that Cold Fusion
can read) by performing a select from the original query where 0=1 so we don't
get any results. Then we turn off debugging, switch the content type, and output
the xml string.
<!--
Name: forxml.cfm
author: Roy Ashbrook
email: royashbrook@yahoo.com
description:
this script demonstrates how to dump for xml query data to the screen as xml
-->
<cfquery name="bad"
datasource="myDSN">
SELECT *
FROM SOMETABLE FOR XML RAW
</cfquery>
<cfquery dbtype="query"
name="good">
select 'xml' as xmlstring from bad where 0=1
union all
select * from bad
</cfquery>
<cfsetting showDebugOutput="No">
<cfcontent type="text/xml">
<cfoutput query="good">
#xmlstring#
</cfoutput>
after playing with it a little, i find more success using the following:
i'd need a little more information. all i did when i posted this was remove the query and replace it with a bogus query. note that in ie it will throw an error unless you wrap it with a root node. i didn't put that in because rss readers or some other automated reader might not want that.
you can try using this:
I tried the above code, but the xmlstring doesnot display for me.. i am getting just a blank page..