Documente Academic
Documente Profesional
Documente Cultură
Plan du jour
z Généralités
z Grammaires
– DTD
– schéma
z Transformations
– XPath
– XSL, FO
z Utilisation avec Java
2 29 janvier 2005
Contexte du cours
3 29 janvier 2005
Représentation de données
4 29 janvier 2005
Stockage de documents
HTML
XML
7 29 janvier 2005
XML (2)
XML (3)
9 29 janvier 2005
10 29 janvier 2005
Announcement
Newsgroups: comp.infosystems.www.misc
Date: Fri, 22 Nov 1996 14:06:58 -0800
From: bosak@atlantic-83.Eng.Sun.COM (Jon Bosak)
Subject: XML proposed
A new language for advanced Web applications has been proposed by a working group of the World
Wide Web Consortium (W3C).
Extensible Markup Language (XML) is a standardized text format specially designed for transmitting
structured data to Web applications. The new language addresses the needs of Web publishers
who encounter limitations in the ability of HTML to express structured data.
1. Information providers can define new tag and attribute names at will.
2. Document structures can be nested to any level of complexity.
3. Any XML document can contain an optional description of its grammar for use by
applications that need to perform structural validation.
12 29 janvier 2005
15 29 janvier 2005
17 29 janvier 2005
18 29 janvier 2005
Documents XML
19 29 janvier 2005
20 29 janvier 2005
z Document valide :
<document>
<a>Avalue
</a>
<b>Bvalue
</b>
</document>
21 29 janvier 2005
22 29 janvier 2005
23 29 janvier 2005
Node NodeList
ExpressionTerminale Element
Utilisation de XML
25 29 janvier 2005
Syntaxe de XML
26 29 janvier 2005
27 29 janvier 2005
28 29 janvier 2005
29 29 janvier 2005
30 29 janvier 2005
31 29 janvier 2005
32 29 janvier 2005
DTD
DTD (2)
34 29 janvier 2005
DTD (3)
35 29 janvier 2005
DTD (4)
36 29 janvier 2005
DTD (5)
37 29 janvier 2005
DTD (6)
<!DOCTYPE company [
<!ELEMENT company ((person|product)*)>
<!ELEMENT person (ssn, name, office, phone?)>
<!ELEMENT ssn (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT office (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT product (pid, name, description?)>
<!ELEMENT pid (#PCDATA)>
<!ELEMENT description (#PCDATA)>
]>
38 29 janvier 2005
DTD (7)
39 29 janvier 2005
DTD (8)
<company>
<person age=“25”
id=“p29432”
manager=“p48293”
manages=“p34982 p423234”>
<ssn>123456789</ssn>
<name>John SMITH</name>
<office>B432</office>
<phone>1234</phone>
</person>
…
40 29 janvier 2005
DTD (9)
…
<person age=“25”
id=“p48293”
manager=“p48293”
manages=“p29432 p24168”>
<ssn>987654321</ssn>
<name>Jim BO</name>
<office>B123</office>
</person>
<product> ... </product>
...
</company>
41 29 janvier 2005
Schémas
42 29 janvier 2005
Schémas (2)
43 29 janvier 2005
Schémas (3)
44 29 janvier 2005
Schémas (4)
45 29 janvier 2005
Schémas (5)
46 29 janvier 2005
Namespaces
47 29 janvier 2005
Namespaces (2)
48 29 janvier 2005
Namespaces (3)
49 29 janvier 2005
Namespaces (4)
50 29 janvier 2005
Namespaces (5)
51 29 janvier 2005
Namespaces (6)
Namespaces (7)
53 29 janvier 2005
Namespaces (8)
<H:html xmlns:H="http://www.w3c.org/TR/REC-html40"
xmlns:mine="file:/DTD/lamienne.dtd">
<H:head>
<H:title>un titre HTML</H:title>
</H:head>
<H:body>
<H:p>un paragraphe HTML</H:p>
<mine:p>ma définition du paragraphe</mine:p>
</H:body>
</H:html>
54 29 janvier 2005
Namespaces (9)
<html xmlns="http://www.w3c.org/TR/REC-html40"
xmlns:mine="file:/DTD/lamienne.dtd">
<head>
<title>un titre HTML</title>
</head>
<body>
<p>un paragraphe HTML</p>
<mine:p>ma définition du paragraphe</mine:p>
</body>
</html>
L’espace de nommage HTML est devenu l’espace par défaut
55 29 janvier 2005
XPath
XPath (2)
57 29 janvier 2005
XPath (3)
58 29 janvier 2005
XPath (4)
XPath (5)
<doc>
<?CR?>
<para>Un <em>premier</em> paragraphe</para>
<para>Un autre paragraphe</para>
</doc>
root
<doc>
text
60 29 janvier 2005
XPath (6)
61 29 janvier 2005
XPath (7)
z Exemples de chemins
– child::para : tous les éléments enfants de type para du nœud
courant
– child::* : tous les éléments enfants du nœud courant
– attribute::nom : sélection d’un attribut du nœud courant dont
l’identifiant est nom
– ancestor::div : sélection de tous les ancêtres du nœud courant
de type div
– self::para : sélection du nœud courant s’il est de type para
– child::*/child::para : sélection de tous les petits fils de type
para
– / : la racine du document
62 29 janvier 2005
XPath (8)
63 29 janvier 2005
XPath (9)
64 29 janvier 2005
XPath (10)
<chapitre>
<titre>…<titre>
<para>…</para>
<note>
<para>… </para>
</note>
<para>…</para>
</chapitre>
65 29 janvier 2005
XPath (11)
<chapitre>
<titre>…<titre>
<para>…</para>
<note>
<para>… </para>
</note>
<para>…</para>
</chapitre>
66 29 janvier 2005
XPath (12)
67 29 janvier 2005
XPath (13)
68 29 janvier 2005
XPath (14)
z Opérations (suite)
– start-with( string, pattern ), ex : ( . , "Téléco" )
– contains( string, pattern )
– string-after
– string-before
– substring
– normalize : enlève les blancs inutiles
– translate : remplace une chaîne par une autre
– concat
– string-length
69 29 janvier 2005
XPath (15)
z Opérations (suite)
– number() : transforme une chaîne de caractères en
un nombre
– round()
– floor()
– ceiling()
– mod()
– name()
70 29 janvier 2005
XPath (16)
z Exemples XPath
– /bib/book[ @price < "60" ]
– /bib/book[ author/@age < "25" ]
– /bib//*[ name() = book ]
z Équivalent à /bib//book !
71 29 janvier 2005
XSL
72 29 janvier 2005
XSL (2)
73 29 janvier 2005
XSL (3)
74 29 janvier 2005
XSL (4)
75 29 janvier 2005
XSL (5)
XSL (6)
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mine="file:/DTD/lamienne.dtd">
…
</xsl:stylesheet>
z Attributs possibles
– default-space="preserve"
– indent-result="no"
77 29 janvier 2005
XSL (7)
<xsl:stylesheet …>
<import href="tables.xsl" />
<import href="composants.xsl" />
…
</xsl:stylesheet>
78 29 janvier 2005
XSL (8)
79 29 janvier 2005
XSL (9)
<xsl:template match="para">
…
</xsl:template>
80 29 janvier 2005
XSL (10)
XSL (11)
82 29 janvier 2005
XSL (12)
<xsl:template match="para">
…
<xsl:apply-templates />
…
</xsl:stylesheet>
z Apply-templates lance le traitement récursif du
document
– La feuille de style est parcourue à nouveau dans sa
totalité pour trouver des templates qui traitent les
enfants
83 29 janvier 2005
XSL (13)
XSL (14)
XSL (15)
86 29 janvier 2005
XSL (16)
<xsl:template match="para">
…
<xsl:value-of select="." />
…
</xsl:stylesheet>
z value-of permet de convertir le nom du nœud
courant (select sur point) en une chaîne de
caractères qui est alors affichée dans le reste
du texte issu de la transformation
87 29 janvier 2005
XSL (17)
88 29 janvier 2005
XSL (18)
89 29 janvier 2005
XSL (19)
90 29 janvier 2005
XSL (20)
91 29 janvier 2005
XSL (21)
92 29 janvier 2005
XSL (22)
93 29 janvier 2005
XSL (23)
94 29 janvier 2005
XSL (24)
XSL (25)
96 29 janvier 2005
XSL (26)
<xsl:choose>
<xsl:when test="position() = 1">red</xsl:when>
<xsl:when test="position() = 2">blue</xsl:when>
<xsl:otherwise>green</xsl:otherwise>
</xsl:choose>
97 29 janvier 2005
XSL (27)
<xsl:for-each select="nom">
Bonjour <xsl:value-of select="." /> !
</xsl:for-each>
98 29 janvier 2005
XSL (28)
99 29 janvier 2005
XSL (29)
XSL (30)
<xsl:for-each select="items/item">
<td><xsl:value-of select="price"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
101 29 janvier 2005
FO
FO (2)
FO (3)
FO (4)
FO (5)
Questions / Remarques