Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Voices That Matter

XML Transference from Data to Layout in Dreamweaver MX

  • Print
  • + Share This
Combine the power of XML and the ease of Dreamweaver and learn how to automate the production of Web pages from XML data.
This chapter is from the book

This chapter is from the book

The speed at which XML was adopted across the business sector was stunning. My first indication of the XML phenomenon came when I was teaching a seminar on maximizing the potential of Dreamweaver 3 at the Seybold conference in Boston. Trying to gauge the audience's level of expertise, I asked how many people had used Dreamweaver before. All but two or three raised their hands. When I asked how many people were familiar with Cascading Style Sheets, only about 1/3 responded. "How many people here use XML in their business?," I asked next. Three-quarters of the audience—an audience of Web developers, mind you—shot up their hands. Clearly, XML was a technology about to explode.

Dreamweaver has long maintained—since version 3, in fact—a strong XML connection. Importing and exporting of the well-formed XML file is only a menu option away. Of course, Dreamweaver assumes you know how to format the XML file properly for importing and how to make the most of exported data. Don't worry if you don't know how to do these things; those topics are part of what will be covered in this chapter.

The standard Dreamweaver XML features are powerful ones, but really only serve as a foundation for what is possible. In this chapter, you'll see how to automate the production of Web pages from XML data. We'll also explore techniques for structuring XML data as content, ready for import into a Dreamweaver template. Finally, we'll look at how to extract the content from a document derived from a template and how to store the information in a data source.

A Brief Introduction to XML

XML, short for Extensible Markup Language, has often been described as a customizable version of HTML. Although this depiction is accurate to a degree, it doesn't really go far enough to distance it from HTML and characterize the language's strengths. To me, XML is pure structure. Each XML tag is only present to contribute to the structure of a document. Better still, the very name of each XML tag describes the content it contains, furthering the structural integrity of the document.

XML files begin with a statement that declares the XML version used. By default, Dreamweaver MX creates XML version 1.0 documents that specify the encoding:

<?xml version="1.0" encoding="iso-8859-1"?>

Internally, XML syntax is similar to HTML with a few key differences:

  • Empty XML elements or tags include a closing slash, like this:

  • <bookImage src="jloweryImage.jpg" width="150" height="150" />
  • The values of attributes must be quoted.

  • Standalone attributes are not permitted. That is, checked as an attribute is not permitted, but checked="true" is.

  • To avoid processing tags within text data, XML uses the CDATA element. CDATA stands for character data, and it is designated by surrounding the text with <![CDATA[ and ]]>. Here's an example:

  • <![CDATA[To designate a table of contents item, enclose 
    the entry with a <toc>...</toc> tag pair.]]>

Structurally, XML documents tend to be made up of multiple sets of tags following the same format. For example, if I were to describe a series of books I've read, the basic form might look like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<books>
 <book>
  <bookTitle name="">
  <authorName name="">
  <bookDescription>
   <![CDATA[]]>
  </bookDescription>
 <book>
</books>

With a number of entries completed, the XML file would look like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<books>
 <book>
  <bookTitle name="Critical Space">
  <authorName name="Greg Rucka">
  <bookDescription>
   -<![CDATA[Bodyguard Atticus Kodiak is hired by someone who attempted
to once kill him.]]> </bookDescription> <book> <book> <bookTitle name="Blackwater Sound"> <authorName name="James W. Hall"> <bookDescription> <![CDATA[Thorn abandons his role as Florida fisherman to stop the
injustice brought by the rich and powerful Brasswell family.]]> </bookDescription> <book> <book> <bookTitle name="Pursuit"> <authorName name="Thomas Perry"> <bookDescription> -<![CDATA[Who is the hunter and who is the hunted in this book
of criminologist vs. serial killer?]]> </bookDescription> <book> </books>

In this example, the overall structural element is the <books> tag, which has three nodes or children in the <book> tags. Within each <book> child, the same descriptive tags are used with varying values. We'll see this exact type of format when we examine XML documents that are exported from Dreamweaver.

  • + Share This
  • 🔖 Save To Your Account