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

XML issue

Enthusiast ,
Jun 21, 2010 Jun 21, 2010

Copy link to clipboard

Copied

I have some CF code that generates dynamic XML files, although it gives a CFM extension to the file our desktop app is able to read them correctly. However we've come across a little bit of a problem.

When the CFM page pulls data from the SQL dbase and creates the XML file, the code fails if any of the text placed into the fields within the XML contain ampersands.

Does anybody know if there is a particular way that we can display ampersands without causing the XML to fail? For now we've had to just remove them

I presume there might also be other characters that could be problomatic within XML's?

Perhaps we have to convert the & to an ascii character?

If so, anybody have any code that covers all problomatic characters to do a CF type REPLACE of all of them in one go?

Thanks

Mark

TOPICS
Advanced techniques

Views

901

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
Participant ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Try replaceing the & with &

Ken Ford

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
Advisor ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Please post a sample of the code that generates the XML.  I suspect that using the XmlFormat() function will solve your issue.

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
Advisor ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Ben Forta's web site contains some chapters from his CF books as PDF files.  These include coverage of XML that you may find useful.

http://www.forta.com/books/0321515463/CFWACK8-2-EChapters.pdf

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
Enthusiast ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Here's the code, between the CFPROCESSINGDIRECTIVE and the CFCONTENT are the necessary SQL statements to obtain the data to populate into the XML, I removed these for the demo purposes

<CFOUTPUT><cfprocessingdirective suppresswhitespace="Yes">

<cfcontent type="text/xml; charset=utf-8"><?xml version="1.0" ?>

<root>

<CFLOOP QUERY="GetCampaignList">
<icon
campuid="#GetCampaignList.campcat_campaign#"
text="#GetCampaignList.camp_icontext#"
alt="#GetCampaignList.camp_alt_text#" />

</CFLOOP>

<CFIF #GetCampaignList2.recordcount# GT "0"><CFLOOP QUERY="GetCampaignList2"><icon
campuid="#GetCampaignList2.camp_uid#"
text="#GetCampaignList2.camp_icontext#"
alt="#GetCampaignList2.camp_alt_text#" />
</CFLOOP></CFIF>


<CFIF #GetCampaignList3.recordcount# GT "0"><CFLOOP QUERY="GetCampaignList3"><icon
campuid="#GetCampaignList3.campcat_campaign#"
text="#GetCampaignList3.camp_icontext#"
alt="#GetCampaignList3.camp_alt_text#" />
</CFLOOP></CFIF>

<CFIF #GetCampaignList4.recordcount# GT "0"><CFLOOP QUERY="GetCampaignList4"><icon
campuid="#GetCampaignList4.camp_uid#"
text="#GetCampaignList4.camp_icontext#"
alt="#GetCampaignList4.camp_alt_text#" />
</CFLOOP></CFIF>

<CFIF #GetCampaignList5.recordcount# GT "0"><CFLOOP QUERY="GetCampaignList5"><icon
campuid="#GetCampaignList5.camp_uid#"
text="#GetCampaignList5.camp_icontext#"
alt="#GetCampaignList5.camp_alt_text#" />
</CFLOOP></CFIF>

<expired value="#ValueList(GetValidCampaigns.camp_uid)#" />


</root></cfprocessingdirective></CFOUTPUT>

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
Enthusiast ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Some characters: ampersand, less than, greater than signs, are reserved in XML and need to be escaped.  You can use XmlFormat for this.  Ben Forta's XML chapters should also be helpful.

EDIT: The XmlFormat function will also escape single and double quotes to allow those characters to be used inside an XML attribute, which is a quoted string.

<CFOUTPUT><cfprocessingdirective
suppresswhitespace="Yes">

<cfcontent type="text/xml;
charset=utf-8"><?xml version="1.0" ?>

<root>

<CFLOOP
QUERY="GetCampaignList">
<icon

campuid="#XmlFormat(GetCampaignList.campcat_campaign)#" /> <!--- etc. --->

Message was edited by: JR "Bob" Dobbs Added comment about quotes.

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
Enthusiast ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

ahh, cool, so it's a little bit like URLEncodedFormat

I have to nip out but will give this a try later today

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
Enthusiast ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

LATEST

Thanks for the help, placing Xmlformat around the text did the trick

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
Resources
Documentation