7 Replies Latest reply on Jun 22, 2010 9:17 AM by ACS LLC

    XML issue

    ACS LLC Level 1

      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?





        • 1. Re: XML issue
          Ken Ford - Fordwebs, LLC Level 2

          Try replaceing the & with &


          Ken Ford

          • 2. Re: XML issue
            JR "Bob" Dobbs-qSBHQ2 Level 3

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

            • 3. Re: XML issue
              JR "Bob" Dobbs-qSBHQ2 Level 3

              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.



              • 4. Re: XML issue
                ACS LLC Level 1

                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" ?>




                <CFLOOP QUERY="GetCampaignList">
                alt="#GetCampaignList.camp_alt_text#" />




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


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


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


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


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



                • 5. Re: XML issue
                  JR "Bob" Dobbs Level 4

                  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.


                  <cfcontent type="text/xml; 
                  charset=utf-8"><?xml version="1.0" ?>
                  campuid="#XmlFormat(GetCampaignList.campcat_campaign)#" /> <!--- etc. --->


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

                  • 6. Re: XML issue
                    ACS LLC Level 1

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


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






                    • 7. Re: XML issue
                      ACS LLC Level 1

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