XML
  Home arrow XML arrow Page 5 - Introduction to Cocoon, XML XSL
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Introduction to Cocoon, XML XSL
By: Olivier Eymere
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 8
    2001-03-22

    Table of Contents:
  • Introduction to Cocoon, XML XSL
  • Getting the tools
  • Installing Tomcat
  • Installing Cocoon
  • Defining your document
  • Creating your xml file
  • Viewing your document in an HTML browser
  • Viewing your document in a WAP browser
  • Viewing your file as a pdf

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Introduction to Cocoon, XML XSL - Defining your document
    (Page 5 of 9 )

    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


     

       

    XML ARTICLES

    - 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...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway