I am writing a function with in my cfc that I am using to return xml. The test
code outisde of my function works perfectly, however when I put the code with
in my function the I get this error.
XML Parsing Error: xml declaration not at start of external entity
Location: http://flex.homesmartagent.com/test.cfm
Line Number 3, Column 1:<?xml version="1.0" encoding="utf-16"?>
^
This is my function code:
<cffunction name="displayDocsListQry" access="remote" returntype="xml"
output="false">
<cfargument name="fileNum" required="no" type="string" />
<cfdirectory action="list" recurse="yes"
directory="#APPLICATION.storePath##APPLICATION.systemInfo.fld_officeCode#/#argum
ents.fileNum#" name="ListDir" />
<cfquery name="DirQry" dbtype="query">
select * from ListDir
where Type = 'Dir'
</cfquery>
<cfprocessingdirective suppresswhitespace="Yes">
<cfcontent type="text/xml; charset=utf-16">
<cfxml variable="xmlobject">
<cfoutput>
<fileNum label="L060001">
<cfloop query="DirQry">
<directory label="#DirQry.name#">
<cfquery name="fileQry" dbtype="query">
select * from ListDir
where Type = 'File' and directory =
'#APPLICATION.storePath##APPLICATION.systemInfo.fld_officeCode#/#arguments.fileN
um#/#DirQry.name#'
</cfquery>
<cfloop query="fileQry">
<document label="#fileQry.name#" />
</cfloop>
</directory>
</cfloop>
</fileNum>
</cfoutput>
</cfxml>
<cfset myvar=toString(xmlobject)>
<cfset mynewvar=replace(myvar, "UTF-8", "utf-16")>
</cfprocessingdirective>
<cfreturn mynewvar />
</cffunction>
Not Nick - 31 Mar 2006 03:22 GMT
You problem seem to be that you have whitespcae in front of the declaration
(<?xml version="1.0" encoding="utf-16"?>) and that is not allowed. Use cfsilent
or cfsetting enablecfoutputonly="true" to make sure that no whitespaces or
linefeeds sneeks by before you function returns your XML