UP PREVIOUS NEXT   Technologies Internet et Education, © TECFA
  2. Le langage XML

2. Le langage XML

Définition un peu plus formelle:

2.1 Les notions de "well-formed" et "valid" d'un document XML

A. "Well-formed" XML documents (arbres)

<?xml version="1.0"?>

<?xml version="1.0" encoding="ISO-8859-1"?>

B. "Valid XML documents"

C. DTD (Document Type Definition)

2.2 Exemples

Exemple 2-1: Bonjour en XML

Données XML
    • On a un document de type <page>
<page>
 <title>Hello Cocoon friend</title>
 <content>
      Here is some content :)
 </content> 
 <comment>
      Written by DKS/Tecfa, adapted from S.M./the Cocoon samples
 </comment>
</page>
Le DTD (à titre d'indication)
<!ELEMENT page  (title, content, comment?)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT content (#PCDATA)>
<!ELEMENT comment (#PCDATA)>
 

Exemple 2-2: Une recette en XML

Source: Introduction to XML by Jay Greenspan,

http://www.hotwired.com/webmonkey/98/41index1a_page5.html?tw=html

<?xml version="1.0"?> 
<list>
 <recipe>
   <author>Carol Schmidt</author>
   <recipe_name>Chocolate Chip Bars</recipe_name>
   <meal>Dinner
     <course>Dessert</course>
   </meal>
   <ingredients>
     <item>2/3 C butter</item>      <item>2 C brown sugar</item>
     <item>1 tsp vanilla</item>     <item>1 3/4 C unsifted all-purpose flour</item>
     <item>1 1/2 tsp baking powder</item>
     <item>1/2 tsp salt</item>      <item>3 eggs</item>
     <item>1/2 C chopped nuts</item>
     <item>2 cups (12-oz pkg.) semi-sweet choc. chips</item>
   </ingredients>
   <directions>
 Preheat oven to 350 degrees. Melt butter; combine with brown sugar and vanilla in large mixing bowl.Set aside to cool.  Combine flour, baking powder, and salt; set aside. Add eggs to cooled sugar mixture; beat well.  Stir in reserved dry  ingredients, nuts, and chips.
 Spread in greased 13-by-9-inch pan. Bake for 25 to 30 minutes until  golden brown; cool.  Cut into squares.
   </directions>
 </recipe>
</list>

UP PREVIOUS NEXT -- TIE