DM 171: Week Nine - Create an XML File

XML Files

Dreamweaver makes it easy for you to create XML files without needing to know the syntax. If you are using a pre-existing schema, you may import it into Dreamweaver’s tag hints; if you are creating your own, Dreamweaver will temporarily add the tag hints as you create them. Note that the screen shots below are from Dreamweaver CS2, the current version varies little.

If you are using a defined schema for your XML file, add it to your tag library from the menu Edit > Tag Libraries… Click on the Plus symbol and choose DTDSchema > Import XML DTD or Schema File. Click OK.

Edit tag library dialog box

Paste in the URL of the DTD you wish to use or navigate to a Schema file on your hard drive using the Browse… button and click OK. Dreamweaver will load in all the tags that are used and assist you with tag hints. For your own self defined XML files, you may skip this step.

From the File > New… dialog box, General tab, Category: Basic Page, Basic page: select XML.

New document dialog window showing Basic page and XML selected

Dreamweaver creates a document with the correct first line to identify the document as an XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>

It is worth noting that Dreamweaver only gives the “Code” view option for XML files, “Split” and “Design” views are grayed out. XML files carry your data but have no look to design.

Visualize the way in which you wish to organize your data. My sample XML file is a short listing of CDs in my collection. I decided to organize the data based on artist/group, then album (CD), then track name.

Start creating tags. Similarly to HTML tags, they begin with < and end with >. If you have a Schema imported, Dreamweaver will assist you with tag hints. If you are creating your own, use tag names with no spaces that are friendly enough that you will remember the context for the data the tags contain. Data must be surrounded by your XML tags or within the tags as attributes. In my sample file, I have created the <discography></discography> tag(s) to contain data about the CDs in my collection.

With each tag you create, Dreamweaver adds it to your tag hints making longer document coding easier. Add attributes as needed, you are in charge! In my example:
<track track_num="1" length="7:05">Track Name</track>
I added track_num to list the position on the CD and length to contain the minutes and seconds of the track. Your tags and attributes will vary with your data needs and the constructs of your imported schema if you are using one.

On to using Spry to view XML dynamically on your page…