Soit le schéma suivant :
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
<xs:element name='magasin'>
4
<xs:complexType>
5
<xs:sequence>
6
<xs:element name='clients'>
7
<xs:complexType>
8
<xs:sequence>
9
<xs:element name='client' type='ClientType' minOccurs='0' maxOccurs='unbounded' />
10
</xs:sequence>
11
</xs:complexType>
12
</xs:element>
13
<xs:element name='commandes'>
14
<xs:complexType>
15
<xs:sequence>
16
<xs:element name='commande' type='CommandeType' minOccurs='0' maxOccurs='unbounded' />
17
</xs:sequence>
18
</xs:complexType>
19
</xs:element>
20
</xs:sequence>
21
</xs:complexType>
22
</xs:element>
23
<xs:complexType name='ClientType'>
24
<xs:sequence>
25
<xs:element name='nom' type='xs:string'/>
26
<xs:element name='prenom' type='xs:string'/>
27
<xs:element name='dateNaissance' type='xs:string'/>
28
<xs:choice>
29
<xs:element name='telephone' type='xs:string'/>
30
<xs:element name='email' type='xs:string'/>
31
</xs:choice>
32
</xs:sequence>
33
<xs:attribute name='clientID' type='xs:integer'/>
34
</xs:complexType>
35
<xs:complexType name='CommandeType'>
36
<xs:sequence>
37
<xs:element name='clientID' type='xs:integer'/>
38
<xs:element name='dateCommande' type='xs:date'/>
39
<xs:element name='dateLivraison' type='xs:date'/>
40
<xs:element name='article' type='xs:string'/>
41
</xs:sequence>
42
</xs:complexType>
43
</xs:schema>
Question
Produisez le plus petit document XML valide possible.
Solution
1
<?xml version="1.0" encoding="UTF-8"?>
2
<magasin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
xsi:noNamespaceSchemaLocation="magasin.xsd">
4
<clients/>
5
<commandes/>
6
</magasin>
Question
Produisez le plus petit document XML valide contenant tous les éléments.
Indice
Un attribut est optionnel par défaut.
Indice
Le type de données "string" permet une chaîne vide mais ce n'est pas le cas des types "date" et "integer".
Indice
L'indicateur <choice>
ne permet qu'un des éléments fils.
Solution
1
<?xml version="1.0" encoding="UTF-8"?>
2
<magasin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
xsi:noNamespaceSchemaLocation="magasin.xsd">
4
<clients>
5
<client>
6
<nom/>
7
<prenom/>
8
<dateNaissance/>
9
<telephone/>
10
</client>
11
<client>
12
<nom/>
13
<prenom/>
14
<dateNaissance/>
15
<email/>
16
</client>
17
</clients>
18
<commandes>
19
<commande>
20
<clientID>12345</clientID>
21
<dateCommande>2013-11-01</dateCommande>
22
<dateLivraison>2013-11-06</dateLivraison>
23
<article/>
24
</commande>
25
</commandes>
26
</magasin>