<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rabidGadfly &#187; XML</title>
	<atom:link href="http://rabidgadfly.com/category/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://rabidgadfly.com</link>
	<description>Simple Solutions to Nagging Coding Problems</description>
	<lastBuildDate>Wed, 19 Oct 2011 13:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Experimenting with Multi-related Selects using Spry</title>
		<link>http://rabidgadfly.com/2007/02/experimenting-with-multi-related-selects-using-spry/</link>
		<comments>http://rabidgadfly.com/2007/02/experimenting-with-multi-related-selects-using-spry/#comments</comments>
		<pubDate>Thu, 22 Feb 2007 14:17:25 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[spry]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=25</guid>
		<description><![CDATA[I recently found myself in need of a multi-related select solution and decided to give Adobe&#8217;s new Spry framework a shot. The first thing I noticed was that, still being in development, there isn&#8217;t much Spry documentation. In lieu of docs Adobe provides several samples which, though useful, did not provide the solution I was [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found myself in need of a multi-related select solution and decided to give <a href="http://labs.adobe.com/technologies/spry/" alt="Adobe Spry">Adobe&#8217;s new Spry framework</a> a shot.</p>
<p>The first thing I noticed was that, still being in development, there isn&#8217;t much Spry documentation. In lieu of docs Adobe provides several samples which, though useful, did not provide the solution I was looking for. My goal is to have two select boxes, each populated by separate but related datasets. In the example I use below, my datasets are brands and subbrands. The subbrands dataset contains a brandID column which is related to the brandID column in the brands dataset. Read on to see how I did it and feel free to leave a comment telling me how I should have done it <img src='http://rabidgadfly.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .<br />
<span id="more-25"></span></p>
<p>First, I set up my two datasets in a component named datasets.cfc.:</p>
<pre>
<code>
<cfcomponent>
   <cffunction name="getBrands" output="no" access="public" returntype="query">
		<cfset tbl = queryNew("brandID,brand")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 1)>
		<cfset querySetCell(tbl, "brand", "GI Joe")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 2)>
		<cfset querySetCell(tbl, "brand", "Star Wars")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 3)>
		<cfset querySetCell(tbl, "brand", "Transformers")>

      <cfreturn tbl />

   </cffunction>

     <cffunction name="getSubbrands" output="no" access="public" returntype="query">
	 	<cfargument name="brandID" type="numeric" required="yes">
		<cfset tbl = queryNew("brandID,subbrand")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 1)>
		<cfset querySetCell(tbl, "subbrand", "Army Rangers")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 1)>
		<cfset querySetCell(tbl, "subbrand", "Navy Seals")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 1)>
		<cfset querySetCell(tbl, "subbrand", "Sigma 6")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 2)>
		<cfset querySetCell(tbl, "subbrand", "Clone Wars")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 2)>
		<cfset querySetCell(tbl, "subbrand", "Jedi Force")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 2)>
		<cfset querySetCell(tbl, "subbrand", "Original Trilogy")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 3)>
		<cfset querySetCell(tbl, "subbrand", "Beast Wars")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 3)>
		<cfset querySetCell(tbl, "subbrand", "Cybertron")>
		<cfset queryAddRow(tbl)>
		<cfset querySetCell(tbl, "brandID", 3)>
		<cfset querySetCell(tbl, "subbrand", "Decepticon")>

		<cfquery name="ds" datasource="query">
			select *
			from tbl
			where brandID = #arguments.brandID#
		</cfquery>

      <cfreturn ds />

   </cffunction>

</cfcomponent>
</code>
</pre>
<p>Next, I created two ColdFusion pages, brands.cfm and subbrands.cfm, that output XML. These will be used as the sources for my selects. The brands.cfm page will output all brands. The subbrands.cfm will expect a URL variable named brandID and will output only the subbrands with that brand ID.</p>
<p>A small diversion: One reason I used external pages to output my XML was that it allowed me to easily insert a new row at the beginning of the dataset. I wanted an additional option with a value of 0 which gets submitted if no brand is selected, In the select box this value is represented by the text: &#8216;Please select a brand&#8217;.</p>
<p>Here are the pages that output XML:</p>
<p>brands.cfm</p>
<pre>
<code>
<cfsetting enablecfoutputonly="no">
<cfset objDatasets = createObject("component","cfc.datasets") />
<cfset qGetBrands = objDatasets.getBrands() />
<cfsavecontent variable="thisXML">
<cfoutput>
<brands>
	<brand>
		<brandID>0</brandID>
		<brandNAME>Select a brand</brandNAME>
	</brand>
	<cfloop query="qGetBrands">
	<brand>
		<brandID>#xmlFormat(brandID)#</brandID>
		<brandNAME>#xmlFormat(brand)#</brandNAME>
	</brand>
	</cfloop>
</brands>
</cfoutput>
</cfsavecontent>
<!--- output XML --->
<cfcontent type="text/xml" reset="true">
<cfoutput>#thisXML#</cfoutput>
<cfabort>
</code>
</pre>
<p>subbrands.cfm</p>
<pre>
<code>
<cfsetting enablecfoutputonly="no">
<cfparam name="url.brandID" default=0>
<cfset objDatasets = createObject("component","datasets") />
<cfset qGetSubbrands = objDatasets.getSubbrands(url.brandID) />

<cfsavecontent variable="thisXML">
<cfoutput>
<subbrands>
	<cfif qGetSubbrands.recordcount eq 0>
		<subbrand>
			<subbrand_id>0</subbrand_id>
			<subbrand_name>No subbrands available</subbrand_name>
		</subbrand>
	<cfelseif qGetSubbrands.recordcount gt 1>
		<subbrand>
			<subbrand_id>0</subbrand_id>
			<subbrand_name>Select a subbrand</subbrand_name>
		</subbrand>
	</cfif>
	<cfloop query="qGetSubbrands">
	<subbrand>
		<subbrand_id>#xmlFormat(subbrand_id)#</subbrand_id>
		<subbrand_name>#xmlFormat(subbrand_name)#</subbrand_name>
	</subbrand>
	</cfloop>
</subbrands>
</cfoutput>

</cfsavecontent>

<cfcontent type="text/xml" reset="true">
<cfoutput>#thisXML#</cfoutput>
<cfabort>
</code>
</pre>
<p>Now the meat of the main page which holds the selects. The first thing I do is load the <a href="http://www.macromedia.com/go/labs_spry_download">Spry js files</a>:</p>
<pre><code>
<script language="JavaScript" type="text/javascript" xsrc="js/spry/xpath.js"></script>
<script language="JavaScript" type="text/javascript" xsrc="js/spry/SpryData.js"></script>
</code></pre>
<p>Next, I define my XML datasets by pointing the js variables to the appropriate XML-generating pages. Notice that my dsSubbrands dataset passes the current value of brandID to the subbrands page. The second parameter in the method calls (&#8220;brands/brand&#8221; and &#8220;subbrands/subbrand&#8221;) refer to the XML node names leading to the records.</p>
<pre><code>
<script type="text/javascript">
var dsBrands = new Spry.Data.XMLDataSet("brands.cfm","brands/brand");
var dsSubbrands = new Spry.Data.XMLDataSet("subbrands.cfm?brandID={dsBrands::brandID}","subbrands/subbrand");
</script>
</code></pre>
<p>And finally, I place the selects by providing repeatingchildren with my dataset names and using the brace format to provide the column names within the source xml ({brandID}, {brandNAME} and {subbrandNAME}):</p>
<pre><code>
<form name="frmSpry" action="#CGI.SCRIPT_NAME#">
<cfoutput>
<table border="0">
<tr>
<td>Brand:</td>
<td><span spry:region="dsBrands" id="brandSelector">
<select spry:repeatchildren="dsBrands" name="brandID"
onchange="document.forms[0].subbrandselect.disabled = true;
dsBrands.setCurrentRowNumber(this.selectedIndex);">
<option spry:if="{ds_RowNumber} == {ds_CurrentRowNumber}" value="{brandID}" selected="selected">{brandNAME}</option>
<option spry:if="{ds_RowNumber} != {ds_CurrentRowNumber}" value="{brandID}">{brandNAME}</option>
</select>

</span>
		</td>
</tr>
<tr>
<td>Subbrand:</td>
<td><span spry:region="dsSubbrands" id="subbrandSelector">
<select spry:repeatchildren="dsSubbrands" name="subbrandselect" >
<option spry:if="{ds_RowNumber} == {ds_CurrentRowNumber}" value="{subbrandNAME}" selected="selected">{subbrandNAME}</option>
<option spry:if="{ds_RowNumber} != {ds_CurrentRowNumber}" value="{subbrandNAME}">{subbrandNAME}</option>
</select>

</span>
		</td>
</tr>
</table>

</cfoutput>
</form>

</code>
</pre>
<p>&#8230;and Spry takes care of the rest.</p>
<p>As I said before, this is a workable solution but I&#8217;m certain there are quicker and more efficient ways to get the same results with Spry without the XML hoops that I jumped through here. You can see a working copy <a href="http://www.rabidgadfly.com/sandbox/spryselects/mrselects.cfm">here</a>.</p>
<p>In researching, I attempted using <a href="http://ray.camdenfamily.com/projects/toxml/">Ray Camden&#8217;s toXML component</a> as well as the <a href="http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/XML12.htm">WDDX functionality provided by ColdFusion</a> but I just kept running problems passing the resulting datasets to the Spry methods.</p>
<p>Let me know if anyone out there has done anything similar using Spry. I&#8217;m interested in seeing the different possible solutions because it seems to me there are many.</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2007/02/experimenting-with-multi-related-selects-using-spry/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Output ColdFusion Query Results to XML</title>
		<link>http://rabidgadfly.com/2006/05/output-coldfusion-query-results-to-xml/</link>
		<comments>http://rabidgadfly.com/2006/05/output-coldfusion-query-results-to-xml/#comments</comments>
		<pubDate>Fri, 19 May 2006 15:51:56 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[beginner]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=7</guid>
		<description><![CDATA[I don&#8217;t claim to be a ColdFusion expert by any stretch of the imagination, but recently I found myself in need of coming up with a way to output query results to an XML file. My example below is based on an absolutely hideous article I stumbled across on the ColdFusion Developer Center. The example [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t claim to be a ColdFusion expert by any stretch of the imagination, but recently I found myself in need of coming up with a way to output query results to an XML file. My example below is based on an absolutely <a title="Hideous CF Doc" href="http://www.adobe.com/devnet/coldfusion/articles/cf_handbk_ch6.html">hideous article</a> I stumbled across on the ColdFusion Developer Center. The example they provide has several errors in syntax: unclosed tags, unclosed quotes, unOPENED pounds, etc. It also only outputs one record!</p>
<p>After about an hour of playing with it I was able to get the code working properly and I thought I&#8217;d share a very basic example. The following code queries a database for names and phone numbers then outputs them all to a file name phonelist.xml in the current path:</p>
<blockquote style="font-family:courier;"><p>
&lt;cfquery name=&quot;qGetPhoneList&quot; datasource=&quot;datasource&quot;&gt;<br />
		select first_name,last_name,phone from employees<br />
	&lt;/cfquery&gt;</p>
<p>	 &lt;!&#8212;Create a temporary variable &quot;tempxml&quot; to hold our XML document&#8212;&gt;</p>
<p>	&lt;cfset tempxml = &quot;&lt;?xml version =&quot;&quot;1.0&quot;&quot;?&gt;<br />
	&lt;!DOCTYPE phonelist [<br />
	&lt;!ELEMENT phonelist (firstname,lastname,phone)&gt;<br />
	]&gt;<br />
	&lt;phonelist&gt;&quot;&gt;<br />
	&lt;cfloop query=&quot;qGetPhoneList&quot;&gt;<br />
	&lt;cfset tempxml = &quot;#tempxml#<br />
	  &lt;cid&gt;#Trim(&quot;#XMLFormat(first_name)#&quot;)#&lt;/cid&gt;<br />
	  &lt;s&gt;#Trim(&quot;#XMLFormat(last_name)#&quot;)#&lt;/s&gt;<br />
	  &lt;r&gt;#Trim(&quot;#XMLFormat(phone)#&quot;)#&lt;/r&gt;<br />
	&quot;&gt;<br />
	&lt;/cfloop&gt;<br />
	&lt;cfset tempxml = &quot;<br />
	#tempxml#<br />
	&lt;/phonelist&gt;&quot;&gt;</p>
<p>	&lt;!&#8212;show the XML in the HTML output &#8212;&gt;<br />
	&lt;P&gt;This is a simple XML document that&#8217;s been generated by the ColdFusion code. &lt;/P&gt;<br />
	&lt;cfoutput&gt;<br />
	  &lt;xmp&gt;<br />
		#tempxml#<br />
	  &lt;/xmp&gt;<br />
	&lt;/cfoutput&gt;</p>
<p>	&lt;!&#8212;write out the XML&#8212;&gt;<br />
	&lt;cfset writePath=#ExpandPath(&quot;phonelist.xml&quot;)#&gt;<br />
	&lt;cfoutput&gt;<br />
	#writePath#&lt;br /&gt;<br />
	&lt;cffile action = &quot;Write&quot; file=&quot;#writePath#&quot; output=&quot;#tempxml#&quot;&gt;<br />
	&lt;/cfoutput&gt;
</p></blockquote>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2006/05/output-coldfusion-query-results-to-xml/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

