Hey All,
I have a method setup it take any query and convert it to XML. It works fine
on CF 7, but on CF 6.1 it fals down and I get this asa result:
[EMAIL PROTECTED]
Here's the code:
<cffunction name="queryToXML" access="public" returntype="string"
output="false">
<cfargument name="queryObj" type="query" required="yes" hint="query
to be converted to XML">
<cfargument name="rootNodeName" type="string" required="no" default="root"
hint="name of the root node">
<cfargument name="rowNodeName" type="string" required="no"
default="data" hint="name of the record level node">
<!--- make an array of the columns for looping --->
<cfset cols = listToArray(ARGUMENTS.queryObj.columnList)>
<!--- vars for iterating --->
<cfset currCol = 1>
<cfset currRec = 1>
<!--- a new xmlDoc --->
<cfset XMLResult = xmlNew()>
<!--- create the root node --->
<cfset XMLResult.xmlRoot = xmlElemNew(XMLResult,ARGUMENTS.rootNodeName)>
<!--- stick record count and column count in attributes of the root node --->
<cfset XMLResult[ARGUMENTS.rootNodeName].xmlAttributes["columns"] =
arrayLen(cols)>
<cfset XMLResult[ARGUMENTS.rootNodeName].xmlAttributes["rows"] =
ARGUMENTS.queryObj.recordCount>
<!--- loop over query and add each row to XML string --->
<cfloop from="1" to="#ARGUMENTS.queryObj.recordCount#" index="currRec">
<cfset
arrayAppend(XMLResult[ARGUMENTS.rootNodeName].xmlChildren,xmlElemNew(XMLResult,ARGUMENTS.rowNodeName))>
<!--- loop over the columns and add the value for each one to the row --->
<cfloop from="1" to="#arrayLen(cols)#" index="currCol">
<cfset currColName = lcase(cols[currCol])>
<cfset currColValue = ARGUMENTS.queryObj[cols[currCol]][currRec]>
<cfset
arrayAppend(XMLResult[ARGUMENTS.rootNodeName][ARGUMENTS.rowNodeName][currRec].xmlChildren,xmlElemNew(XMLResult,currColName))>
<cfset
XMLResult[ARGUMENTS.rootNodeName][ARGUMENTS.rowNodeName][currRec][currColName].xmlText
= currColValue>
</cfloop>
</cfloop>
<cfreturn XMLResult>
</cffunction>
My guess is the xmlElemNew() function is to blame as no elements seem to be
being added. That function exists on 6.1 and 7, but on 7 there is a new
optional argument which I am not using.
Can anyone see why the above code on CFMX 6.1 would produce what it is (see
above)?
Thanks in advance
Cheers
Bryan Stevenson B.Comm.
VP & Director of E-Commerce Development
Electric Edge Systems Group Inc.
phone: 250.480.0642
fax: 250.480.1264
cell: 250.920.8830
e-mail: [EMAIL PROTECTED]
web: www.electricedgesystems.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:234197
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54