- A Brief Introduction to XML
- Exporting Template Content to XML
- Manually Importing from XML
- Automated Import to Template
Manually Importing from XML
On the flip side of exporting XML data from templates, Dreamweaver has the capability to import XML data into a template to create a new template-derived document. For the import operation to work as intended, the XML must be in a specific format. Each XML tag corresponds to a template region or markup. Both XML syntax used during exportthe standard Dreamweaver <item> syntax and the editable region names as XML tagsare supported for import, with the same restrictions. For complex templates, including any template markup other than just editable regions, the standard Dreamweaver syntax must be used.
Perhaps the best way to understand the format required for import is to examine an exported XML file. Here's a simple example:
<?xml version="1.0"?> <templateItems template="/Templates/planet.dwt" codeOutsideHTMLIsLocked="false"> <item name="diameter"><![CDATA[ <P> 7926 miles ]]></item> <item name="moons"><![CDATA[ <P> 1 ]]></item> <item name="planetImage"><![CDATA[<IMG
SRC="assets/Images/earth.gif" ALIGN="TOP" WIDTH="72" HEIGHT="72"
VSPACE="0" HSPACE="0" ALT="Earth Photo" BORDER="0">]]></item> <item name="doctitle"><![CDATA[ <TITLE>Earth</TITLE> ]]></item> <item name="orbital_period"><![CDATA[ <P> 365 days, 6 hours, 9 minutes, 13 seconds ]]></item> </templateItems>
The first thing to notice is the tag identifying the template from which the document was derived. Another important aspect is the orderor rather the lack of orderof the item entries. In the original file, the editable regions appeared in this sequence: doctitle, planetImage, diameter, orbital_period, and moons. In the exported data file, they are written in this order: diameter, moons, planetImage, doctitle, and orbital_period. This is one of the major advantages of an XML file over a less structured layout of informationthe order the data is written is irrelevant to the order of its final presentation.
Dreamweaver imports XML files written in both standard and editable region-based syntax. Either of the following two formats is supported:
<templateItems template="/Templates/planet.dwt"
codeOutsideHTMLIsLocked="false">...</templateItems> <planet template="/Templates/planet.dwt">...</planet>
When the File, Import, XML into Template command is given and a properly formatted XML file is selected, the data and the template instance are merged and a new document is created immediately.
NOTE
The approach described in this section is not the only way to combine data and templates to create new pages. To see how you can generate HTML pages directly from a data source, look at Chapter 5, "Automating Static Page Production from a Data Source."