Home arrow XML arrow Page 6 - Introduction to Cocoon, XML XSL

Creating your xml file - XML

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.

TABLE OF CONTENTS:
  1. Introduction to Cocoon, XML XSL
  2. Getting the tools
  3. Installing Tomcat
  4. Installing Cocoon
  5. Defining your document
  6. Creating your xml file
  7. Viewing your document in an HTML browser
  8. Viewing your document in a WAP browser
  9. Viewing your file as a pdf
By: Olivier Eymere
Rating: starstarstarstarstar / 9
March 22, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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:

<contact> <name> <first-name></first-name> <last-name></last-name> </name> <address> <street></street> <city></city> <state></state> <country></country> </address> <phone></phone> <e-mail></e-mail> </contact>

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:


<contact> <name> <first-name>Homer</first-name> <last-name>Simpson</last-name> </name> <address> <street>122 West 1st Avenue</street> <city>Springfield</city> <state>ZZ</state> <country>USA</country> </address> <phone>1-555-555-1111</phone> <e-mail>h.simpson@springfieldnuclear.com</e-mail> </contact>

With properly defined dtds and an xml template filling in data should be a relatively painless task.



 
 
>>> More XML Articles          >>> More By Olivier Eymere
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: