This tutorial will guide you through setting up Tomcat and Cocoon to serve XML pages, then you will create a DTD, XML file and three XSL stylesheets so that you can view your data in your desktop browser, a cell phone browser and a pdf file.
Now that we know what our data should look like we create the xml file. According to the dtd our xml file must contain all of these elements in (more or less) this structure:
To begin create a file called homer.xml and open it in a text editor. The first line of the xml file is the XML declaration:
<?xml version="1.0"?>
Every xml and xsl document should begin with the XML declaration. This declares that this is an xml document and which version of xml you are using.
Tags of the form <?...?> are processing instructions (PI). Processing instructions are instructions that are passed to the application that will be using the xml document. The first word after the <? is called the target which is the application that the instructions will be passed to. The rest of the PI contains the instructions to be passed to the target. In this case the target is the xml application and we are telling it that we are using xml version 1.0.
The next is our document type declaration. This is where we associate our xml file with the dtd we created. All declarations use the tag <!...>. The document type declaration looks like:
<!DOCTYPE contact SYSTEM "contact.dtd">
Next we want to add a PI for cocoon so that Cocoon knows that we want it to perform stylesheet transformations for us:
<?cocoon-process type="xslt"?>
Finally we can populate our file with data. At this point filling in the data is pretty simple, just add data values between the tags: