Skip to main content
Known Participant
November 25, 2008
Answered

CFContent + CFOutput needs to be on same line?

  • November 25, 2008
  • 3 replies
  • 1482 views
Hi everyone, recently I have been devloping a simple page for my webapp the spits out some XML data. I have it working perfectly, just like I want. However, the last line:

<cfcontent type="text/xml" reset="yes" /><cfoutput>#variables.xmldata#</cfoutput>

needs to have both the cfcontent and cfoutput tags on the same line or else the XML does not output.
Can anyone explain why this is happening?
This topic has been closed for replies.
Correct answer JR__Bob__Dobbs-qSBHQ2
quote:

Originally posted by: freedomflyer
But why should it matter? Cannot an XML file or output have whitespace in it?


An XML document can contain whitespace, but a well formed XML document should start with the XML declaration such as:
<?xml version="1.0" encoding="UTF-8" ?>
This lets the parser know that the document is XML and optionally what encoding is used. Some parsers may be forgiving of whitespace or other content before the declaration others are not. I recommend you err on the side of conformance and begin your XML with the declaration.

3 replies

Known Participant
November 25, 2008
I understand that I need the declaration, that makes good sense. It lets the parser know what is going on and how to deal with it. However, I still do not understand why my code runs fine like this:

<cfcontent type="text/xml" reset="yes" /><cfoutput>#variables.xmldata#</cfoutput>

and it DOESN'T work like this (same code, but the cfoutput is a line down):

<cfcontent type="text/xml" reset="yes" />
<cfoutput>#variables.xmldata#</cfoutput>

Once again, thank you for your help and patience
Inspiring
November 25, 2008
<cfcontent type="text/xml" reset="yes" /> <!--- there is a newline character here --->
<cfoutput>#variables.xmldata#</cfoutput> <!--- the XML declaration starts on this line, after whitespace created by the newline --->

Using <cfcontent type="text/xml" reset="yes" /><cfoutput>#variables.xmldata#</cfoutput> omits any whitespace before the XML is output.
Known Participant
November 25, 2008
Oh, your previous post summed it up, I just didn't read it correctly. This makes sense - but almost "scares" me about something so extremely tiny as a newline, even if the XML is well formed and everything is packaged up nicely.
But, with great power comes GREAT responsibility, I guess :)
Thanks again guys!
Known Participant
November 25, 2008
But why should it matter? Cannot an XML file or output have whitespace in it?
JR__Bob__Dobbs-qSBHQ2Correct answer
Inspiring
November 25, 2008
quote:

Originally posted by: freedomflyer
But why should it matter? Cannot an XML file or output have whitespace in it?


An XML document can contain whitespace, but a well formed XML document should start with the XML declaration such as:
<?xml version="1.0" encoding="UTF-8" ?>
This lets the parser know that the document is XML and optionally what encoding is used. Some parsers may be forgiving of whitespace or other content before the declaration others are not. I recommend you err on the side of conformance and begin your XML with the declaration.
Inspiring
November 25, 2008
cfcontent reads whitespace.