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

Defining your document - 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
Your server environment is ready to go. Now we can actually start creating xml files. The first step is to create a Document Type Definition (dtd). The dtd tells the xml parser what information is allowed in the xml file and defines the format of the data. If the xml file does not fit into the constraints of the dtd the xml parser will give you an error and stop parsing the document. In our example we are creating a 'contact' element which has a name, address, phone number and email address. The dtd will define which tags must be part of a contact element and what kind of data will be in each tag.

It is not actually necessary to create a dtd for such a simple xml file, but it is important to use dtds when you are creating more sophisticated documents. Advantages of using dtds are that they ensure that your xml files are valid and well-formed and that you have all of the required data in the document. Using dtds also helps create standardization. Once you have created a dtd for a 'contact' it can be used in any place where contact information is required. This helps ensure that your data is consistent through out the company. Dtds also make it easier to communicate your data structures to others. If someone wants to interact with your applications or web site, for example, you could use dtds to show them your data structures.

To create your dtd, change directories to $TOMCAT_HOME/webapps/cocoon and create a directory called 'address'. Then change directories to address, create a file called contact.dtd and open it up in a text editor

The first step is to define you root element:


<!ELEMENT contact (name,address,phone,e-mail)>

In the line above we defined an element called contact which contains the elements name, address, phone and e-mail. Any time we use this dtd we must have a contact element which contains all of the child elements.

Next we will define the name element:


<!ELEMENT name (first-name,last-name)> <!ELEMENT first-name (#PCDATA)> <!ELEMENT last-name (#PCDATA)>

The first line defines the name element as containing first-name and last-name elements. The next two lines define first-name and last-name elements as text elements.

Following the same logic we can fill in the address, phone and e-mail elements.


<!ELEMENT address (street,city,state,country)> <!ELEMENT street (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)> <!ELEMENT country (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT e-mail (#PCDATA)>

The entire dtd looks like this:

<!-- contact.dtd --> <!ELEMENT contact (name,address,phone,e-mail)> <!ELEMENT name (first-name,last-name)> <!ELEMENT first-name (#PCDATA)> <!ELEMENT last-name (#PCDATA)> <!ELEMENT address (street,city,state,country)> <!ELEMENT street (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)> <!ELEMENT country (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT e-mail (#PCDATA)>




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