This content has been marked as final. Show 7 replies
Please define "blows up".
Is it possible that CustName or another field contains characters such as the ampersand that need to be escaped with the XmlFormat function?
This is the Error I receive, and yes I had forgotten the XMLFormat option.
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Only one top level element is allowed in an XML document. Error processing resource
Is your error being generated by ColdFusion or a browser/xml viewer?
The code below creates a well formed XML document.
Is it possible that some code that is not included in your sample is responsible for the error?
Is is possible that your text contains smart quotes or other characters not properly handled by the XmlFormat function?
Are you using ToString() when converting the XML object to text?
> The XML page cannot be displayed
> Cannot view XML input using XSL style sheet. Please correct the error and then
> click the Refresh button, or try again later.
> Only one top level element is allowed in an XML document. Error processing
This is a browser error, not a CF error.
Do a view-source on what's delivered to the browser... from the error
message it looks like it's not XML you're sending it.
Just a quick note: I use XmlFormat tag for each and every string or date/time field I'm retrieving from a database when the output is to an XML file. The reason is simple: I don't know every keystroke that's going to be used - correctly or incorrectly - by the users. Since it's also one of the cf tags that will accept embedded "#" characters, it's easy to use even in a script with multiple queries. A quick example:
<cfquery name="get_Data1" ...>
[Select statements here]
<cfquery name="get_Data2" ...>
[Select statements here]
<cfxml variable="outXML" casesensitive="yes">
<cfquery name="get_Data3" dbtype="query"
SELECT User_Last_Name, User_First_Name, User_Address
<cfloop query="getData3" startrow="1" endrow="1">
<user_name last="#XmlFormat('#getData3.User_Last_Name#')#" first="XmlFormat('#getData3.User_First_Name#')#" />
<user_address street="#XmlFormat('#getData3.User_Address#')#" />
If I haven't mistyped something, the browser reads the output as ...
<?xml version="1.0" encoding="UTF-8" ?>
<user_name last="Spencer" first="Herb" />
<user_address street="4th & Pine Streets" />
The little CPU time required for the XmlFormat tags to process is minor compared to the cost of searching each table to find the ONE character here that would cause an error.
I did mis-type something... the </cfoutpout> and </cfxml> tags at the end are in the wrong order ... Sorry!