Le langage XML: création de balises

Preview:

DESCRIPTION

Le langage XML: création de balises. Plan 1.1 Introduction 1.2Un premier document XML 1.3Analyseurs et documents bien formés XML 1.4Analyser un document XML avec msxml 1.5Caractères 1.5.1caractères autorisés 1.5.2Espace - PowerPoint PPT Presentation

Citation preview

2001 Prentice Hall, Inc. All rights reserved.

Le langage XML:création de balises

Plan1.1 Introduction1.2 Un premier document XML1.3 Analyseurs et documents bien formés XML1.4 Analyser un document XML avec msxml1.5 Caractères

1.5.1 caractères autorisés1.5.2 Espace

1.5.3 Références d ’entité et entités prédéfinies 1.5.4 Utiliser Unicode dans un document XML

1.6 balises1.7 sections CDATA1.8 Espaces de noms XML 1.9 Etude de cas: Une application de planification

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.1 Un document XML simple contenant un message

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 5.1 : intro.xml -->

4 <!-- introduction simple a XML -->

5

6 <monMessage>

7 <message>Bienvenue dans le monde XML!</message>

8 </monMessage>

élément racine

Élément fils

2001 Prentice Hall, Inc. All rights reserved.

Fig. 1.2 document XML visualisé avec IE5 (msxml).

2001 Prentice Hall, Inc. All rights reserved.

Fig. 1.3 Message d’erreur pour une balise non fermée

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.4 document XML contenant des caractères arabes

1 <?xml version = "1.0"?>23 <!-- Fig. 5.4 : lang.xml -->4 <!-- Demonstrating Unicode -->56 <!DOCTYPE welcome SYSTEM "lang.dtd">78 <welcome>9 <from>1011 <!-- Deitel and Associates -->12 &#1583;&#1575;&#1610;&#1578;&#1614;&#1604;13 &#1571;&#1606;&#1583;1415 <!-- entity -->16 &assoc; 17 </from>1819 <subject>2021 <!-- Welcome to the world of Unicode -->22 &#1571;&#1607;&#1604;&#1575;&#1611; 23 &#1576;&#1603;&#1605;24 &#1601;&#1610;&#1616;25 &#1593;&#1575;&#1604;&#1605; 2627 <!-- entity -->28 &text; 29 </subject>30 </welcome>

2001 Prentice Hall, Inc. All rights reserved.

Affichage du document de la Fig. 1.4

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.5 document XML contenant des informations décrivant un livre.

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 5.5 : usage.xml -->

4 <!-- utilisation des éléments et des attributs -->

5

6 <?xml:stylesheet type = "text/xsl" href = "usage.xsl"?>

7

8 <book isbn = "999-99999-9-X">

9 <title>Deitel&amp;s XML Primer</title>

10

11 <author>

12 <firstName>Paul</firstName>

13 <lastName>Deitel</lastName>

14 </author>

15

16 <chapters>

17 <preface num = "1" pages = "2">Bienvenue</preface>

18 <chapter num = "1" pages = "4">XML facile</chapter>

19 <chapter num = "2" pages = "2">Les Elements XML?</chapter>

20 <appendix num = "1" pages = "9">Entites</appendix>

21 </chapters>

22

23 <media type = "CD"/>

24 </book>

Processing instruction (PI) déclarant une page de style

2001 Prentice Hall, Inc. All rights reserved.

Affichage du document de la Fig. 1.5 en utilisant une page de style XSL

2001 Prentice Hall, Inc. All rights reserved.

Comment décider entre un élément et un attribut XML?

• Définir plutôt des éléments– Quand les données sont structurées– Quand le texte encadré par les balisés est long– Quand les données changent souvent

• Définir plutôt des attributs– Texte de petite taille– Liste de valeurs prédefines

• Visibilité – plutôt des éléments• Container- Contenu – éléments

• Définir des attributs ou des élements en fonction de l'application

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.6 document XML décrivant une lettre

1 <?xml version = "1.0"?>23 <!-- Fig. 5.6: letter.xml -->

4 <!-- lettre formatée par XML -->

56 <letter>

78 <contact type = "from">

9 <name>Jane Doe</name>10 <address1>Box 12345</address1>

11 <address2>15 Any Ave.</address2>

12 <city>Othertown</city>13 <state>Otherstate</state>14 <zip>67890</zip>

15 <phone>555-4321</phone>

16 <flag gender = "F"/>17 </contact>

1819 <contact type = "to">

20 <name>Jane Doe</name>21 <address1>123 Main St.</address1>

22 <address2></address2>23 <city>Anytown</city>

24 <state>Anystate</state>

25 <zip>12345</zip>26 <phone>555-1234</phone>27 <flag gender = "M"/>

28 </contact>

29

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.6 document XML décrivant une lettre (Partie 2)

30 <salutation>Dear Sir:</salutation>

31

32 <paragraph>It is our privilege to inform you about our new

33 database managed with <bold>XML</bold>. This new system

34 allows you to reduce the load on your inventory list

35 server by having the client machine perform the work of

36 sorting and filtering the data.</paragraph>

37

38 <paragraph>The data in an XML element is normalized, so

39 plain-text diagrams such as

40 /---\

41 | |

42 \---/

43 will become gibberish.</paragraph>

44

45 <closing>Sincerely</closing>

46 <signature>Ms. Doe</signature>

47

48 </letter>

2001 Prentice Hall, Inc. All rights reserved.

Affichage du document de la Fig. 1.6 en utilisant une page de style XSL

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.7 Utilisation d’une section CDATA.

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 5.7 : cdata.xml -->

4 <!-- section CDATA contenant du code C++ -->

5

6 <book title = "C++ How to Program" edition = "3">

7

8 <sample>

9 // commentaire C++

10 if ( this-&gt;getX() &lt; 5 &amp;&amp; value[ 0 ] != 3 )

11 cerr &lt;&lt; this-&gt;displayError();

12 </sample>

13

14 <sample>

15 <![CDATA[

16

17 // commentaire C++

18 if ( this->getX() < 5 && value[ 0 ] != 3 )

19 cerr << this->displayError();

20 ]]>

21 </sample>

22

23 C++ How to Program by Deitel &amp; Deitel

24 </book>

2001 Prentice Hall, Inc. All rights reserved.

Affichage du document de la Fig. 1.7

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.8 exemple d’utilisation des espaces de nom

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 5.8 : espace.xml -->

4 <!-- espace de nom -->

5

6 <repertoire xmlns:texte = "urn:iutsud:textInfo"

7 xmlns:image = "urn:iutsud:imageInfo">

8

9 <text:file filename = "book.xml">

10 <text:description>une liste de livres</text:description>

11 </text:file>

12

13 <image:file filename = "funny.jpg">

14 <image:description>une image amusante</image:description>

15 <image:size width = "200" height = "100"/>

16 </image:file>

17

18 </repertoire>

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.9 utilisation des espaces de nom par défaut

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 5.9 : defautespace.xml -->

4 <!-- utiliser les espaces de nom par défaut -->

5

6 <directory xmlns = "urn:iutsud:textInfo"

7 xmlns:image = "urn:iutsud:imageInfo">

8

9 <file filename = "book.xml">

10 <description>une liste de livres</description>

11 </file>

12

13 <image:file filename = "funny.jpg">

14 <image:description>une image amusante</image:description>

15 <image:size width = "200" height = "100"/>

16 </image:file>

17

18 </directory>

Espace de nom par défaut

2001 Prentice Hall, Inc. All rights reserved.

Exemples de documents XML avec espace de noms

• Le format XLink– Définir des liens entre les différents documents

<annuaire xmlns:xlink="http://www.w3.org/1999/xlink">

<personne Xlink:href="etudiant/etudiant62.html"

Xlink:title="Louis Henri" />

</annuaire>

2001 Prentice Hall, Inc. All rights reserved.

Avantages du XML

• Structuration de l’information• Définitions partagées• Facilite le développement des standards

– TEI pour l’édition de corpus (http://www.tei-c.org/index.xml)– Dublin Core (http://dublincore.org/) et OLAC

(http://www.language-archives.org/) pour les bibliothèques virtuelles

– XCES pour l’annotation morpho-syntaxique (http://www.xces.org/)

– OWL pour l’annotation sémantique (http://www.w3.org/TR/owl-features/)

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.10document XML décrivant un emploi du temps

1 <?xml version = "1.0"?>

2

3 <!-- Fig. 5.10 : temps.xml -->

4 <!-- Emploi du temps en XML -->

5

6 <planificateur>

7

8 <annee valeur = "2001">

9

10 <date mois = ”9" jour = "15">

11 <note heure = "1430">rendez-vous chez le médecin</note>

12 <note heure = "1620">cours d’informatique</note>

13 </date>

14

15 <date mois = ”12" jour = ”25">

16 <note>Noel</note>

17 </date>

18

2001 Prentice Hall, Inc. All rights reserved.

Outline

Fig. 1.10 document XML décrivant un emploi du temps (Partie 2)

19 <date mois = ”10" jour = "20">

20 <note heure = "0900">Conseil de département</note>

21 </date>

22

23 <date mois = ”10" jour = "20">

24 <note heure = "1900">Anniversaire de Jean</note>

25 </date>

26

27 <date mois = ”11" jour = "20">

28 <note heure = "1300">Réunion pédagogique</note>

29 </date>

30

31 </annee>

32

33 </planificateur>

2001 Prentice Hall, Inc. All rights reserved.

Fig. 1.11 Application Java/JAXP utilisant le document xml décrivant

un emploi du temps.

Recommended