CFLib.org – Common Function Library Project

sqlXMLToCFXML(doc, qry)

Last updated April 9, 2007

author

Russel Brown

Version: 1 | Requires: CF6 | Library: DataManipulationLib

Description:
Takes a query and a name for a root element and creates a XML string (not xmlObject) that can then be used within ColdFusion. This is conversion only for MSSQL generated XML.

Return Values:
Returns a string.

Example:

<cfquery datasource="mydatasource" name="xmlQuery">
SELECT * FROM myTable FOR XML AUTO, ELEMENTS
</cfquery>

<cfset retVar = sqlXMLToCFXML(doc="myRoot",qry=xmlQuery)/>

Parameters:

Name Description Required
doc Name for root level element. Yes
qry Query to convert. Yes

Full UDF Source:

<!---
 Converts a query of XML generated by MSSQL to readable XML string.
 
 @param doc 	 Name for root level element. (Required)
 @param qry 	 Query to convert. (Required)
 @return Returns a string. 
 @author Russel Brown (russel.brown@universalmind.com) 
 @version 1, April 9, 2007 
--->
<cffunction name="sqlXMLToCFXML" access="public" output="false" returntype="Any" hint="This function will take a multiple row query result and turn it into a CF XML var.">
      <cfargument name="doc" type="String" required="false" default="xml" />
      <cfargument name="qry" type="Query" required="true" />

      <cfset var x = "" />
      <cfset var y = "" />
      <cfset var retXML = "" />

      <cfset x = listFirst(arguments.qry.columnList)>
      <cfloop index="y" from="1" to="#arguments.qry.recordCount#">
         <cfset retXML = retXML & arguments.qry[x][y]>
      </cfloop>

      <cfset retXML = "<#arguments.doc#>" & retXML & "</#arguments.doc#>">

      <cfreturn retXML>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson