Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFContent + CFOutput needs to be on same line?

New Here ,
Nov 25, 2008 Nov 25, 2008
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?
TOPICS
Getting started
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Nov 25, 2008 Nov 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 t...
Translate
LEGEND ,
Nov 25, 2008 Nov 25, 2008
cfcontent reads whitespace.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2008 Nov 25, 2008
But why should it matter? Cannot an XML file or output have whitespace in it?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 25, 2008 Nov 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2008 Nov 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 25, 2008 Nov 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2008 Nov 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!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 25, 2008 Nov 25, 2008
LATEST
freedomflyer wrote:
> But, with great power comes GREAT responsibility, I guess 🙂
> Thanks again guys!
>

Yes, HTML is, by design, very forgiving of extra whitespace. When one
starts moving to XML, AJAX and other techniques, whitespace is not so
easily forgiven. Luckily ColdFusion has many ways to manage it, when it
is important. Besides what you have just used, there is
<cfsilent></cfsilent>, <cfsetting enabbleCFOutputOnly = true> and
whitespace management settings in the administrator to just name a couple.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources