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

Returning XML from CFC

Contributor ,
Oct 27, 2006 Oct 27, 2006

Copy link to clipboard

Copied

I'm trying to return either an xml string or xmlObject through a webservice. When I dump the return I get the following code (Some of the code)
<thankyoucards> <submission> <username>returnVariable</username> <orderdate>returnVariable</orderdate> <jobnumber>returnVariable</jobnumber> <contactname>returnVariable</contactname>

XMLParse chokes on attempting to display this.

In my cfc I'm using the cfsavecontent tag to create the xml

<cfset myXML="">

<!--- generate xml --->
<cfsavecontent variable="myXML">
<thankyoucards>
<submission>
<username>returnVariable</username>
<orderdate>returnVariable</orderdate>
<jobnumber>returnVariable</jobnumber>
<contactname>returnVariable</contactname>
<email>returnVariable</email>
<contactphone>returnVariable</contactphone>
<mailclass>returnVariable</mailclass>
<dropdate>returnVariable</dropdate>
<pieces>returnVariable</pieces>
<fileupload>returnVariable</fileupload>
<wordupload>returnVariable</wordupload>
<addfiles>returnVariable</addfiles>
<cardtype>returnVariable</cardtype>
<comments></comments>
</submission>
</thankyoucards>
</cfsavecontent>
<cfreturn myXML>
How can I return the xml so that I can parse it into an xml object?
Thanks for the help.

TOPICS
Advanced techniques

Views

456

Translate

Translate

Report

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

Contributor , Oct 28, 2006 Oct 28, 2006
Doh! Thanks to both for the wakeup call. Good thing it's a weekend. Again, thanks.

Mark

Votes

Translate

Translate
Guide ,
Oct 28, 2006 Oct 28, 2006

Copy link to clipboard

Copied

Try adding an xml declaration. Use appropriate encoding (UTF-8, etc).

Votes

Translate

Translate

Report

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 ,
Oct 28, 2006 Oct 28, 2006

Copy link to clipboard

Copied

> Try adding an xml declaration. Use appropriate encoding (UTF-8, etc).
> <cfset myXML="">
> <!--- don't put anything between opening cfsavecontent tag and xml declaration
> --->
> <cfsavecontent variable="myXML"><?xml version='1.0' encoding='UTF-8'?>

Or just use <cfxml>, which is a tag created *specifically* to create XML
documents...

--
Adam

Votes

Translate

Translate

Report

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
Guide ,
Oct 28, 2006 Oct 28, 2006

Copy link to clipboard

Copied

Adam's suggestion is better. I forgot about cfxml...

Votes

Translate

Translate

Report

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
Contributor ,
Oct 28, 2006 Oct 28, 2006

Copy link to clipboard

Copied

Doh! Thanks to both for the wakeup call. Good thing it's a weekend. Again, thanks.

Mark

Votes

Translate

Translate

Report

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 ,
Oct 30, 2006 Oct 30, 2006

Copy link to clipboard

Copied

Using <cfsavecontent...< can work as well. It does have the advantage
over the <cfxml...> in that you can set you own declaration for example
to use a different character encoding then <cfxml...> uses. But to use
it, you need to make sure you have no whitespace at the beginning of the
string otherwise xmlParse() will choke.

<!--- generate xml --->
<cfsavecontent variable="myXML"><thankyoucards>
<submission>

Votes

Translate

Translate

Report

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 ,
Oct 30, 2006 Oct 30, 2006

Copy link to clipboard

Copied

LATEST
> Using <cfsavecontent...< can work as well. It does have the advantage
> over the <cfxml...> in that you can set you own declaration for example
> to use a different character encoding then <cfxml...> uses. But to use

Good point!

When you first said this, I thought "nah... <cfxml> must be able to do that
too...", but no.

They explain how to fudge it here:

http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000352.htm

I can only think that the author of that document must have been cringing
as they typed that. What a pathetic thing to have to do. Why would they
not just have an ENCODING option on <cfxml>, eg:

<cfxml variable="x" encoding="UTF-16">

Or something?

--
Adam

Votes

Translate

Translate

Report

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
Documentation