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?

       

      Thanks

       

      Mark

        • 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.

               

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

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

                 

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

                • 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.

                   

                  <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.

                  • 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

                     

                     

                    Thanks

                     

                    Mark

                    • 7. Re: XML issue
                      ACS LLC Level 1

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

                       

                      Mark