Dreamweaver's Visual XML Authoring EnvironmentAs you saw in the previous section, working with XML and XSL files by hand can become a chore. With the release of Dreamweaver 8, however, Macromedia brought about new and revamped features for building, interacting with, and binding XML and XSL files so that you don't have to do it manually. Specifically, these features include:
Before we dive into all these topics, however, let's begin by creating our first XML file. Creating an XML DocumentBefore we can begin working with XSL pages, the Bindings panel, or application objects, we must build our XML file. After the XML file has been created, we can turn our attention to working with the other XSL features built into Dreamweaver 8. Let's get started. Keeping in line with the Dorknozzle application, let's build an XML file that defines data for our Dorknozzle employees. What purpose this data serves and for which application it will be designed is irrelevant at this point. What we care about is creating the XML file that defines the name, title, department, and email for all the company employees. To create the XML file, start by choosing File, New. The New Document dialog appeasr. Choose the XML option from the Basic Page category and click Create. The XML file appears in Code view with the following line at the top of the page: <?xml version="1.0" encoding="iso-8859-1"?> As you can see, the first line of code defined in the XML file is the XML declaration. This declaration must be included at the beginning of each XML document. Not only does it specify the XML version to the browser, it also outlines the character set to be used in the document. Now that the XML document has been created, add the following data, beginning at line 2: <employees> <employee > <name>Ada</name> <title>Admin Assistant</title> <department>Administration</department> <email>ada@dorknozzle.info</email> </employee> <employee > <name>Agnes</name> <title>Accountant</title> <department>Accounting</department> <email>agnes@dorknozzle.info</email> </employee> <employee > <name>Cammy</name> <title>Content Manager</title> <department>Marketing</department> <email>cammy@dorknozzle.info</email> </employee> <employee > <name>Dave</name> <title>Developer</title> <department>Engineering</department> <email>dave@dorknozzle.info</email> </employee> <employee > <name>Ferris</name> <title>Founder</title> <department>Executive</department> <email>ferris@dorknozzle.info</email> </employee> <employee > <name>Herb</name> <title>Representative</title> <department>Human Resources</department> <email>herb@dorknozzle.info</email> </employee> <employee > <name>Mike</name> <title>Director</title> <department>Marketing</department> <email>mike@dorknozzle.info</email> </employee> <employee > <name>Pat</name> <title>Programmer</title> <department>Engineering</department> <email>pat@dorknozzle.info</email> </employee> <employee > <name>Tina</name> <title>Tech Writer</title> <department>Administration</department> <email>tina@dorknozzle.info</email> </employee> <employee > <name>Wally</name> <title>Webmaster</title> <department>Marketing</department> <email>wally@dorknozzle.info</email> </employee> </employees> Save your file as employees.xml. Looking at the data, you'll probably notice some interesting aspects. First and foremost, the tags say a lot about the data contained within them, right? This is XML at its finestit's describing the data contained within the tags. First we have a list of employees, hence the <employees> tag. Second, we have groups of individual employees, therefore we have various <employee> tags uniquely identified by the id attribute. Within each <employee> tag, we have tags that define the employees name (<name>), title (<title>), department (<department>), and email address (<email>). Second, and possibly the most obvious even if you're not an HTML developer, is that none of these tags are recongnizable. Remember, with XML, you are responsible for defining the tags. XML is used to define data, not to structure it. Ultimately, the browser doesn't care what XML tags you're using because it won't attempt to parse anything out of the file. This is where XSL come in. Let's do that next. Creating an XSL TransformationNow that the XML file has been created, we'll want some way of structuring the data so that it's presentable in the browser. As mentioned earlier, the eXtensible Stylesheet Language (XSL) is the markup language used for structuring XML pages such that the data becomes legible by the browser. You might be thinking that we'll be creating the XSL file by hand as we did in the opening section of this chapter, right? Think again. Dreamweaver 8's handling of XSL files is such that you can create an XSL file, tie the XSL file to an XML file, and then simply preview the results by pressing F12 to see the dynamic XML transformation to HTML in the browser. To create the XSL page, follow these steps:
As you can see from the callouts in Figure A.4, the XML file's tags are organized in a hierarchal schema tree as nodes and elements within the Bindings panel. These nodes, represented by the root node (employees), trickle down to expose repeating nodes (employee), and elements (name, title, department, and email). You'll also notice that the unique id attribute is outlined as a parameter within the panel. More on this later. Notice that not much occurred in our XSL page. For the most part, the Bindings panel was populated with a schema that represents our XML file. Aside from that, nothing. Our next task is to present the data elements within the XML file in the XSL page by way of dynamic text. You can create dynamic text using a variety of methods, let's discuss each next. Dynamic TextNow that you've effectively tied the XSL file to your XML document, you'll undoubtedly want some method for displaying the data contained within the XML tags onto the page and ultimately onto the browser. Enter dynamic text. Dynamic text, not unlike the dynamic text we've worked with in the last few chapters of the book, allows you to dynamically represent the data contained within the XML tags on the XSL page such that when we preview the page in the browser, the data is pulled from the XML file, stylized by the XSL file, and dynamically transformed into an HTML file that the browser understands. To work with dynamic text, follow these steps:
To preview the page in the browser, press the F12 key. Instantly Dreamweaver creates a temp HTML file (the transformed file) and presents it in the browser, similar to Figure A.7. Figure A.7. The first employee in our XML file is presented, structured for the browser.As you can see from Figure A.7, the first employee in our employees.xml file (Ada) is shown in a cleanly formatted table. After you pick your jaw up off the floor, you'll quickly come to realize that we created ten employees in our XML file, yet only one appears. This is where the Repeat Region application object comes in. Repeating RegionsIn the previous section, you saw how easy it was to work with dynamic text in an XSL document. Unfortunately, the previous section only went as far as allowing you to present the first employee in the XML file. In this section, we'll explore the addition of repeating regions within the table in the XSL file. By including a repeating region, we can effectively display all the records contained within the XML file. To add a repeating region to the table in the XSL page, follow these steps:
Save your work and test the results in the browser by pressing the F12 key. As you can see from Figure A.9, all the records in the XML file are now displayed in the HTML table in the browser. In the preceding example, we used the Repeat Region application object to display all the data contained within the XML file. But what if we wanted to filter results based on a specific parameter? Perhaps we want to select a specific employee with the ID of 1005 from the XML file. To accomplish this, you can easily build a filter within the Repeat Region dialog that filters based on the id attribute of the <employee> tag in the XML file. To do this, follow these steps:
Save your work and test the results in the browser by pressing the F12 key. This time, only one record (the employee with an ID of 1005Ferris) appears in the table in the browser. Conditional RegionsConditional regions, similar to the filters you can create in the Repeat Regions dialog, allow you to build a filtering expression for data within your XML file. To work with conditional regions, follow these steps:
Save your work and test the result in the browser by pressing the F12 key. This time, one record (Ferris) appears in the table in the browser. Working with RSS FeedsQuite possibly one of the hottest trends, aside from Web services, is that of RSS. Originally developed by Netscape, Rich Site Summary (RSS) is an XML format for syndicating web content. A website that wants to allow other sites to publish some of its content creates an RSS document and registers the document with an RSS publisher. A user that can read RSS-distributed content can then use the content on a different site. Syndicated content includes such data as news feeds, events listings, news stories, headlines, project updates, excerpts from discussion forums, and even corporate information. Although numerous websites are devoted to the topic of helping you publish and distribute RSS feeds, you need look no further than Dreamweaver 8. With Dreamweaver 8's built-in XML/XSL transformation integration, consuming RSS feeds in your website is a snap. To work with RSS feeds, follow these steps:
Save your work and test the results in the browser by pressing the F12 key. Instantly, Slick Deals feeds are presented to you within the browser, similar to Figure A.14. Figure A.14. Slick Deals news feeds are shown in the browser. |