Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Creating a Spry XML data set

by Raymond Camden

Raymond Camden
  • raymondcamden.com

Content

  • A basic example
  • A dynamic example

Created

2 March 2009

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ColdFusion 8 data set Dreamweaver CS4 dynamic website Spry XML

Requirements

Prerequisite knowledge

Basic HTML and XML knowledge and familiarity with the Dreamweaver workspace, site management, and building websites.

User level

Intermediate

Required products

  • Dreamweaver CS4 (Download trial)
  • ColdFusion 8 (Download trial)

Sample files

  • xml_dataset_sample.zip (3 KB)

In Creating an HTML data set, I demonstrated how easy HTML data sets are to use in Dreamweaver CS4. HTML data sets are tables, or other structured bits of HTML, that Spry can load via Ajax. Once loaded, this data can be sliced and diced (that is, sorted, filtered, and more) in a variety of ways, making it rather easy to develop dynamic Ajax applications without needing any knowledge of JavaScript or server-side technology.

In this article I'll introduce XML data sets. I'll demonstrate that using XML data sets is as easy as using HTML data sets in Dreamweaver CS4. I'll also discuss how you can use ColdFusion to dynamically create the XML used by Spry.

Note: Before you begin, be sure you have a website defined in Dreamweaver and then download the sample files that accompany this article. Unzip the files into a new folder. You can name this anything you want; I used the name dwarticlexml. You will also need to have ColdFusion 8 installed and running with the site used in Dreamweaver. Be sure you install the example applications with ColdFusion as the database used for this tutorial's dynamic example will use them. For more information about defining a site, refer to Setting up a Dreamweaver site in Dreamweaver Help. For help with ColdFusion, read Setting up a ColdFusion development environment.

A basic example

Let's start by looking at some sample XML data that you will be using for your Spry data sets. In Dreamweaver, open the file jedilist.xml, which is part of the sample files that accompany this article. Here is a snippet of the XML code with a few rows removed to save space:

<?xml version="1.0" encoding="UTF-8"?> <jedis> <jedi> <name>Raymond Camden</name> <age>35</age> <alignment>dark</alignment> </jedi> <jedi> <name>Scott Stroz</name> <age>40</age> <alignment>light</alignment> </jedi> <jedi> <name>Todd Sharp</name> <age>32</age> <alignment>light</alignment> </jedi> <jedi> <name>Scott Pinkston</name> <age>36</age> <alignment>dark</alignment> </jedi> </jedis>

The XML file contains a list of Jedis. Each Jedi has a name, age, and alignment (dark or light; the dark ones are the fun ones). XML is structured data. Note that each person begins with a <jedi> tag and end with </jedi>. Each name is wrapped with a <name> tag, and so on. It is critical that the XML you use be well formed. Although HTML can be a bit forgiving, XML is very strict about how you structure the file. Next, create a new file in Dreamweaver.

  1. Right-click inside the folder you created and select New File. Name your new file test.html. Double-click the file to open it in Dreamweaver.
  2. Place your cursor after the <body> tag. Ok, now for the fun part.
  3. On the Insert menu, select Data > Spry Data Set. This opens the window shown in Figure 1.
The default window for inserting a Spry Data Set.
Figure 1. The default window for inserting a Spry Data Set.
  1. By default Dreamweaver will want to create an HTML data set. Simply switch the Data Type to XML.
  2. Click the Browse button to tell Dreamweaver where to find your data file. Select jedilist.xml from your site folder. Dreamweaver will read the file and display a tree-style view of your XML data (see Figure 2).
Dreamweaver has parsed in the XML and understands the basic structure of your data.
Figure 2. Dreamweaver has parsed in the XML and understands the basic structure of your data.
  1. Ok, now note the data preview. Although it looks kind of right, it only seems to see one row of data. That's because the Row element selected above is "jedis", not "jedi". Remember, you wrapped the entire XML file in the jedis tag, but each individual jedi was wrapped in a jedi tag. Figure 3 shows what happens when you select the jedi node.
Now Dreamweaver knows how to list out your data from the XML file.
Figure 3. Now Dreamweaver knows how to list out your data from the XML file.

Dreamweaver has recognized that the jedi tag wraps each individual row of data. The preview confirms this. Click Next.

  1. If you stepped through Creating an HTML data set, then this part of the wizard should be familiar. Here you can tell Spry how to treat each column.

    This is a purely optional step, but it helps with sorting if you tell Spry when columns aren't basic string types. Your data is rather simple. Only the age column is numeric. So go ahead and select the age column and select Number from the Type drop-down menu. Next, set the Sort column (towards the bottom) to Name. This will sort the XML data by the name column.

Specifying settings for the columns and sorting.
Figure 4. Specifying settings for the columns and sorting.
  1. Click next to the go to the last step. Under insert options, select Insert Table and click the Done button.

Your HTML page should look like this:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script src="../SpryAssets/xpath.js" type="text/javascript"></script> <script src="../SpryAssets/SpryData.js" type="text/javascript"></script> <script type="text/javascript"> <!-- var ds1 = new Spry.Data.XMLDataSet("jedilist.xml", "jedis/jedi", {sortOnLoad: "name", sortOrderOnLoad: "ascending"}); ds1.setColumnType("age", "number"); //--> </script> </head> <body> <div spry:region="ds1"> <table> <tr> <th spry:sort="name">Name</th> <th spry:sort="age">Age</th> <th spry:sort="alignment">Alignment</th> </tr> <tr spry:repeat="ds1"> <td>{name}</td> <td>{age}</td> <td>{alignment}</td> </tr> </table> </div> </body> </html>

If you open your browser to this file, you can now see the XML data has been dynamically loaded into the HTML. The data was sorted automatically by the name, but you can actually click the header of each column and sort the data any way you like.

A dynamic example

In the previous example, I demonstrated Spry working with an XML file that is hard coded on the file system. For people without a proper application server like ColdFusion, this manual solution may be the only solution they have. But if you do have ColdFusion installed, then why not use the power of CFML to help you create dynamic XML to be used within your Spry applications? Let's look at how you can use ColdFusion to generate XML.

Note: For help with setting up a ColdFusion application server, read Setting up a ColdFusion development environment.

  1. Create a new file named artdata.cfm. Open it and remove the default HTML that Dreamweaver put into the file.
  2. Select the Server Behaviours tab in Dreamweaver. You'll see a list of items that you may, or may not, have to complete to tell Dreamweaver about your local ColdFusion installation. This should be a pretty simple set of tasks and will only need to be done once. If your Server Behaviours panel looks like the one in Figure 5, you are all set.
Figure 5. A properly configured Server Behaviors panel leaves you feeling well rested and assured that everything will turn out OK in the end.
Figure 5. A properly configured Server Behaviors panel leaves you feeling well rested and assured that everything will turn out OK in the end.
  1. As item 6 says in the Server Behaviors panel, click the + button and choose Recordset. This opens a panel where you can configure a database query. For the name, use Art. For the database, select cfartgallery. The table should already be set as APP.ART (see Figure 6). Leave columns as All and click OK.
Settings for the new Recordset.
Figure 6. Settings for the new Recordset.

Dreamweaver will insert the following query into your template.

<cfquery name="Art" datasource="cfartgallery"> SELECT * FROM APP.ART </cfquery>
  1. Now you need to generate XML from this data. You don't have enough time to do a full explanation of the code below. Also note that there are multiple ways to generate XML within ColdFusion. Your code will simply create an XML document from the query and serve it to the user. Copy and paste the following code to the file, after the query.
<cfxml variable="xml"> <art> <cfoutput query="art"> <piece> <name>#artname#</name> <description>#description#</description> <price>#price#</price> <image>#largeimage#</image> </piece> </cfoutput> </art> </cfxml> <cfcontent type="text/xml" reset="true"><cfoutput>#xml#</cfoutput>

The <cfxml> tag is used to create an XML document from text inside it. I wrap the outer portion of my XML with the <art> tag. Next I loop over the query using <cfoutput>. I wrap each record with <piece> tags and then output a few of the columns. (Note that the <cfsavecontent> tag could have been used instead of <cfxml>. ColdFusion provides many ways to solve common problems!)

  1. Save the file and open it in your browser. You should see generated XML from the art information in the database. I selected to output the name, price, and largeimage columns from the table. I could have chosen other columns as well. What you select from the database and how you output it in XML is really up to your application.

Ok, so now you have ColdFusion generating XML from the database. Even if you aren't a ColdFusion developer (not yet anyway), I hope you can appreciate how simple it was to create the XML dynamically.

Note: To find out how to generate XML easily from ColdFusion queries (and other forms of data), refer to my project, toXML. This is a simple ColdFusion Component (CFC) that handles the grunt work of creating XML.

Next, you want to get it into an Ajax-based application.

  1. Create a new file in Dreamweaver and name in test2.html.
  2. Click right after the body tag.
  3. On the Insert menu, select Spry Data Set. Switch the type to XML and select artdata.cfm. As with the previous example, Dreamweaver can parse the XML, but you have to actually click the piece item to let Dreamweaver know what part of the XML represents a row. Your screen should resemble Figure 7.
First step in inserting our new dynamic XML.
Figure 7. First step in inserting our new dynamic XML.
  1. Click Next. Once again you have the option to tell Dreamweaver how to treat the data. Select the price column and set the type to number. Under Sort Column, set the value to Name. Click Next.
  2. In the previous example you told Dreamweaver to insert a table. This time you are going to get a bit fancy and create a master/detail layout—select this option (it's the second one), and then click Setup.

    What this option screen represents is how the page will determine what is shown in the master list versus what is shown in the detail (see Figure 8). Dreamweaver used the first column, name, for the master list. This means your page will create a list of names. You can then click that name to get a detail of the other columns: description, price, and image. You can choose to modify this, but the defaults are actually rather good, so for now, just click OK. Click Done and Dreamweaver inserts the code onto the page.

Setup options for a Master/Detail layout.
Figure 8. Setup options for a Master/Detail layout.
  1. Before you view the page, you need to make one quick change. You included the image of the art piece on the page, but it would be nice to show the actual picture instead of just the file name. Find the following snippet in the file:
<div class="DetailColumn">{image}</div>

...and change it to:

<div class="DetailColumn"><img src="/cfdocs/images/artgallery/{image}"></div>

This creates a dynamic image based on the data that Spry loads in from the XML.

  1. To finish, save the file and view it in your browser.

Note that you can now click and browse the art pieces—all without writing one line of JavaScript! (Well, obviously some JavaScript was involved, but Dreamweaver wrote it for you!)

Note: In addition to HTML and XML, Spry also supports TSV and CSV data sets. These are tab- and comma-separated files. Although not common, if you have data in that format you can make use of it in Spry. Spry also supports JSON. JSON is probably the best way to create data for Ajax-based applications as it tends to have the smallest size footprint. Dreamweaver doesn't support easy creation of JSON-based data sets; however, once you get more comfortable with it you should definitely look into it. ColdFusion 8 added native support for generating JSON.

Where to go from here

In this article, I demonstrated how easy Dreamweaver makes it to work with Spry. For people uncomfortable with JavaScript, Dreamweaver CS4 goes a long way to making it as easy as a mouse-click to develop Ajax applications. To learn more, check out the Spry Technology Center and the Spry site on Adobe Labs.

More Like This

  • Styling and inserting a Spry Menu Bar 2.0 widget with the Adobe Widget Browser
  • Using the Adobe Widget Browser
  • Beginner's guide to databases
  • Managing multiple subscriptions in PHP
  • Building a subscribe/unsubscribe app in PHP with Dreamweaver CS3
  • XSL overview
  • Which server-side technology should I choose?
  • Creating master and detail ColdFusion pages
  • Creating user-defined functions for ColdFusion 8 in Dreamweaver CS4
  • Creating a ColdFusion upload page in Dreamweaver CS4

Tutorials and samples

Tutorials

  • Understanding HTML5 semantics: Changed and absent elements
  • Mobile app with PhoneGap: Submitting to the Apple App Store
  • PhoneGap and Dreamweaver: Releasing on iOS
  • Mobile app with PhoneGap: Creating a release build for Android

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Dreamweaver user forum

More
04/23/2012 Resolution/Compatibility/liquid layout
04/20/2012 using local/testing server with cs5 inserting images look fine in the split screen but do not show
04/18/2012 Ap Div help
04/23/2012 Updating

Dreamweaver Cookbook

More
11/07/2011 Simple social networking share buttons
09/20/2011 Registration form that will generate email for registrant to validate
08/21/2011 Spry Accordion - Vertical Text - Auto Start on Page Load - Mouse Over Pause
08/17/2011 Using cfdump anywhere you like

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement