House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Search flex

February 09, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28             

Home /  Groups /  Adobe Flex

Fighting with whitespace

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stefan Richter
03/24/2009 08:45 AM

Hi all, This issue is driving me a little nuts. I'm building a web based API to my database. I POST some data from   Flex (or FMS), I get back XML. That works pretty well (but note I am   not a CF programmer by trade...). What I'm struggling with is suppressing all the whitespace in the XML.   My CFM page essentially looks like this (simplified): <cfsetting enablecfoutputonly="yes"> <cfprocessingdirective pageencoding = "utf-8" suppressWhiteSpace =   "Yes"> <cfxml variable="userXML">   <cfoutput><result action="none" status="error"></cfoutput>   <cfoutput><message>no action defined</message></cfoutput>   <cfoutput></result></cfoutput> </cfxml> <cfoutput>#toString(userXML)#</cfoutput> </cfprocessingdirective> If I hit this from FMS and trace the response I see this: <?xml version="1.0" encoding="UTF-8"?> <result action="none" status="error"><message>no action defined</ message></result> It has a big fat empty line between the first and second line of   content (I assume the first line is added on the fly by CF by me   setting the page encoding). I'm wondering what suppressWhiteSpace = "Yes" actually does because   intially I did not wrap each line of my output in cfoutput tags, but   that resulted in all the tab intends to be outputted as well. Are there any best practices on how to format XML responses in CF? And one more question: what exactly is returned to me if I omit the   toString conversion on the last line (toString(userXML)) ? My FMS   trace shows coldfusion.xml.XmlNodeList@140e0f2 and I have no clue how I could then process that, which is why I ended   up with toString (note FMS uses ActionScript 1 so I do not have the   luxuries of E4X and the like for parsing, instead FMS is very picky   when it comes to XML formatting). Cheers Stefan

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
03/24/2009 09:15 AM

----- Excess quoted text cut - see Original Post for more ----- In your example code, you don't need any of the CFOUTPUT tags except the last one. CFXML lets you build an XML document object in memory. That said, I don't know if that'll affect your whitespace output. In my experience, I usually find it's easier just to get rid of whitespace at design time if I care about it, which I might in the case of XML. ----- Excess quoted text cut - see Original Post for more ----- FMS uses ActionScript 1 still? Yikes! Anyway, CFXML creates an XML document object in memory. You can't just output one of those as a string; when you do, you get the funky syntax you saw. That is basically telling you that there's an object of type coldfusion.xml.XmlNodeList at a certain location in memory. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stefan Richter
03/24/2009 10:50 AM

Thanks Dave. So basically I am not doing anything inherently wrong, correct? When you say 'easier just to get rid of > whitespace at design time if I care about it, ' what do you mean by that? Design time as in when it arrives on the FMS   side? I'll also take your advice and try to put my cfoutput tags on a diet! Cheers Stefan On 24 Mar 2009, at 13:12, Dave Watts wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
03/24/2009 12:15 PM

> So basically I am not doing anything inherently wrong, correct? No, not really. > When you say 'easier just to get rid of whitespace at design time if I care about it, ' > what do you mean by that? Design time as in when it arrives on the FMS side? No, I mean on the CF side: <cfxml variable="userXML"><result action="none" status="error"><message>no action defined</message></result></cfxml> <cfcontent reset="yes"><cfoutput>#userXML#</cfoutput> The CFCONTENT tag will clear the output buffer so that you don't have any whitespace from the previous empty lines. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stefan Richter
03/24/2009 01:00 PM

Thanks again, I will try that. I have not managed to do away with the cfoutput tags however since   often my XML return contains dynamically generated values, I think I   therefore need the cfoutput. But I discovered something else - and this is almost too stupid to   comprehend and should be written on a warning sign when you install   CF: in the CF admin under settings there is an option ?Enable   Whitespace Management?.  Guess what - it wasn't checked. Seems   unchecked by default. Checking it seems to eliminate *a lot* of leading whitespace issues I   had. Could it be that without this checked the suppressWhiteSpace   option of cfprocessingdirective does nothing at all? Regards, Stefan On 24 Mar 2009, at 16:10, Dave Watts wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
03/24/2009 01:40 PM

> I have not managed to do away with the cfoutput tags however since > often my XML return contains dynamically generated values, I think I > therefore need the cfoutput. That makes sense. > But I discovered something else - and this is almost too stupid to > comprehend and should be written on a warning sign when you install > CF: in the CF admin under settings there is an option ?Enable > Whitespace Management?.  Guess what - it wasn't checked. Seems > unchecked by default. Right, this is disabled by default. For most uses - HTML generation, for example - this simply isn't that important. And it does add some overhead. > Checking it seems to eliminate *a lot* of leading whitespace issues I > had. Could it be that without this checked the suppressWhiteSpace > option of cfprocessingdirective does nothing at all? No, the two are separate. However, if I recall correctly, CFPROCESSINGDIRECTIVE only gets rid of white space generated by CF tags. It doesn't get rid of the line where the CF tag was, so you end up with blank lines. Also, and I hadn't noticed this in your original email, you're not supposed to use both PAGEENCODING and SUPPRESSWHITESPACE attributes in the same CFPROCESSINGDIRECTIVE tag. Again, though, my preference is to use CFCONTENT TYPE="RESET" to avoid leading whitespace before my output, when generating non-HTML output. Finally, all this is easily avoided if you can use either web services or Flash Remoting with CF. CF supports both. But you did mention that you're using FMS, and I don't know enough about that to comment. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more informati

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stefan Richter
03/24/2009 03:20 PM

Thanks, would love to use Remoting but this project will end up as a   public API over HTTP and I need to hit it from FMS too (which btw can   do Remoting if needed). Cheers Stefan On 24 Mar 2009, at 17:36, Dave Watts wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
03/24/2009 03:30 PM

> Thanks, would love to use Remoting but this project will end up as a > public API over HTTP and I need to hit it from FMS too (which btw can > do Remoting if needed). SOAP is a public API, isn't it? You could write a single CFC method which can be called via SOAP and Remoting, and offer either. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stefan Richter
03/24/2009 03:50 PM

Yeah SOAP would be an option but since I'm not that familiar with it   (and I'll have to support this thing) I'll stick to the custom XML   responses for now. Cheers Stefan On 24 Mar 2009, at 19:25, Dave Watts wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
03/24/2009 04:30 PM

> Yeah SOAP would be an option but since I'm not that familiar with it > (and I'll have to support this thing) I'll stick to the custom XML > responses for now. Well, just for future reference, it's very simple. You just write a CFC, add a function to that CFC with ACCESS="REMOTE", and return whatever object you want to return. For cross-platform happiness, stick to simple values, arrays or typed objects (essentially structures for which you've created a corresponding CFC). You don't have to write any XML at all that way. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
03/24/2009 09:20 AM

----- Excess quoted text cut - see Original Post for more ----- I missed this part in my initial response, but the first line is added by CFXML automatically. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
03/24/2009 02:40 PM

Here is one way I have dealt with this issue. <cfsilent>     <cfquery name="markers" datasource="sor">         SELECT             l.id,             l.name AS location,             l.lead,             l.longitude,             l.latitude,             a.name AS activity,             j.ranking,             r.stars,             r.rank,             a.icon                    FROM             locations l INNER JOIN                 location_activity_join j ON l.id = j.locationID INNER JOIN                     activities a ON j.activityID = a.id INNER JOIN                         location_activity_ranks r ON j.ranking = r.id                        WHERE             published = 1                    ORDER BY             l.name     </cfquery> </cfsilent><cfcontent type="text/xml" reset="yes"><?xml version="1.0" encoding="iso-8859-1"?> <markers><cfoutput query="markers" group="location"><cfset cat=''><marker lng="#val(longitude)#" lat="#val(latitude)#" id="#id#" name="#xmlFormat(trim(location))#" category="<cfoutput><cfset cat = #listAppend(cat,xmlFormat(rereplace(trim(activity),'[^[:alnum:]]','','ALL')))#></cfoutput>#cat#" activities="<cfoutput>#xmlFormat(trim(activity))# #repeatString('*',val(stars))#<br/></cfoutput>" /> </cfoutput> </markers>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stefan Richter
03/24/2009 03:25 PM

Thanks Ian. I'm getting satisfactory results now by using: <cfprocessingdirective suppressWhiteSpace = "Yes"> <cfsetting enablecfoutputonly="yes"> combined with the checked box in the CF Admin and <cfcontent type="text/xml" reset="yes" before my output. Thanks all. On 24 Mar 2009, at 18:38, Ian Skinner wrote: ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists