XML – TD1 : DTD et XML Schema - LISIC

Transcription

XML – TD1 : DTD et XML Schema - LISIC
Université du Littoral Côte d’Opale
M1 Info / 2014–2015
XML – TD1 : DTD et XML Schema
www-lisic.univ-littoral.fr/~hoock/Enseignements/ULCO/XML/tdXML01.pdf
Enseignant : Jean-Baptiste Hoock ([email protected])
Exercice 1 : XML
Les documents XML suivants sont-ils corrects ? Trouvez et corrigez les éventuels erreurs.
1.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
2.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html [
<!ELEMENT html (head,body)>
<!ELEMENT head (title)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT body (p+)>
<!ELEMENT p (#PCDATA)>
]>
<html>
<head><title>Hello, World</title></head>
<body><p>Hello, World</p></body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<p>This is a test. This is a test of the <em>
3:
<strong>Emergency</em> Broadcast System.</strong></p>
1:
2:
3.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note [
<!ELEMENT note (Message)>
<!ELEMENT Message (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ATTLIST note date CDATA #REQUIRED>
]>
<note date="12/11/2007">
<!-- This is a comment -->
<Message><to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body></message>
</note>
<note date="13/11/2007">
1
<message><to>Jani</to>
<from>Tove</from>
21:
<heading>Re: Reminder</heading>
22:
<body>Ok!</body></message>
23: </note>
19:
20:
4.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
5.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
6.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="points">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="point">
<xs:complexType>
<xs:attribute name="x" type="xs:unsignedShort" use="required"/>
<xs:attribute name="y" type="xs:unsignedShort" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html [
<!ELEMENT html (head,body)>
<!ELEMENT head (title)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT body (p+)>
<!ELEMENT p (#PCDATA)>
]>
<html>
<head><title>Paragraphs</title></head>
<body><p>This is a paragraph.<br/>
<p>This is another paragraph.<br/>
<p>Third paragraph.</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description rdf:about=http://www.AcronymFinder.com/>
<dc:title>Acronym Finder</dc:title>
<dc:description>The Acronym Finder is a world wide
web (WWW) searchable database of more than 169,000
abbreviations and acronyms about computers,
technology, telecommunications, and military
acronyms and abbreviations.</dc:description>
<dc:subject>
<rdf:Bag>
2
13:
14:
15:
16:
17:
18:
19:
20:
21:
7.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
8.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
<rdf:li>Astronomy</rdf:li>
<rdf:li>Literature</rdf:li>
<rdf:li>Mathematics</rdf:li>
<rdf:li>Music</rdf:li>
<rdf:li>Philosophy</rdf:li>
</rdf:Bag>
</dc:subject>
</rdf:Description>
</rdf:RDF>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html [
<!ELEMENT html (head,body)>
<!ELEMENT head (title)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT body (p|b|i|br)+>
<!ELEMENT p (b|i)+>
<!ELEMENT br EMPTY>
<!ELEMENT b (#PCDATA|i)*>
<!ELEMENT i (#PCDATA|b)*>
]>
<html><body>
<p><b><i>This paragraph is bold and italic.</b></i></p><br/>
<p><i><b>This paragraph is italic and bold.</i></b></p><br/>
</body></html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (work)>
<!ELEMENT work (title,author)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ATTLIST work type CDATA #REQUIRED>
<!ATTLIST work date CDATA #REQUIRED>
]>
<catalog>
<work date=’1906’ type="prose">
<title>The Gift Of The Magi</title>
<author>O. Henry</author>
</work>
<work type=’poem’>
<title>The Raven</title>
<author>Edgar Allen Poe</author>
</work>
<work type=’play’ date=’1601’>
<author>William Shakespeare</author>
<title>Hamlet</title>
</work>
</catalog>
3
9.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
10.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
11.
1:
2:
3:
4:
5:
<?xml version="1.0" encoding="UTF-8"?>
<letter>
<date>December 11, 2002</date>
<addressee>
<name>Melvile Dewey</name>
<address_one>
Columbia University</address_one><address_two>New York, NY
</address_two>
</addressee>
<greeting>Dear Melvile,</greeting>
<paragraph>I have been reading your ideas concerning nature of
librarianship, and <italics>I find them very intriguing</italics>.
I would love the opportunity to discuss with you ...</paragraph>
<list><item>Monday, 2-4</item>
<item>Tuesday, 3-5</item>
<item>Thursday, 1-3</item>
</list>
<paragraph>We hope you can join us.</paragraph>
<closing>Sincerely, S. R. Ranganathan</closing>
</letter>
<?xml version="1.0"?>
<!DOCTYPE dictionary [
<!ELEMENT dictionary (word*)>
<!ELEMENT word (update|name|description|definition)*>
<!ELEMENT update EMPTY>
<!ATTLIST update date CDATA #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ATTLIST name is_acronym CDATA #IMPLIED >
<!ELEMENT description (#PCDATA)>
<!ELEMENT definition (#PCDATA)>
]>
<dictionary>
<word>
<update date="2002-12-23"/>
<name is_acronym="true">XML</Name>
<description>eXtensible Markup Language</description>
</word>
<word>
<update date="2002-12-23"/>
<name is_acronym="true">POP</name>
<definition default>Post Office Protocol</definition>
<definition>Point Of Purchase</definition>
</dictionary>
<?xml version="1.0" encoding="UTF-8"?>
<domain type=’kvm>
<name>domain</name><
<memory>524288</memory>
<vcpu>2</vcpu>
4
6:
7:
8:
9:
10:
11:
12:
13:
14:
12.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
13.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
<features><acpi/><pae/>
<clock offset=’utc’>
<disk type=’block’ device=’cdrom’>
<driver name=’qemu’ type=’raw’/>
<source file=’/path/to/image.iso’/>
<tar get dev=’hdc’ bus=’ide’/>
<readonly/></name>
</disk>
</domain>
<?xml version="1.0" encoding="UTF-8"?>
<name>Oyster Soup</name>
<author>Eric Lease Morgan</author>
<copyright holder=Eric Lease Morgan>&copy; 2003</copyright>
<ingredients>
<list>
<item>1 stalk of celery
<item>1 onion
<item>2 tablespoons of butter
<item>2 cups of oysters and their liquor
<item>2 cups of half & half
</list><cost>total cost < 36 euro </cost>
</ingredients>
<process><P>Begin by sauteing the celery and onions in butter until
soft.
Add oysters, oyster liquor, and cream. Heat until the oysters float.
Serve in warm bowls.</p>
<p><i>Yummy!</p></i>
</process>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE list [
<!ELEMENT list (list|integer)*>
<!ELEMENT integer (#PCDATA)>
<!ATTLIST list list CDATA #IMPLIED>
]>
<list>
<integer>3</integer>
<list list="list of lists of integers">
<list>
<integer>4</integer>
<integer>9</integer>
</list>
</list>
<integer>13</integer>
<list/>
</list>
5
Exercice 2 : XML et DTD
Soit le document XML suivant :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<facture>
<etabliepar> Sociéte Orégram </etabliepar>
<date> 3 décembre 2008 </date>
<areglerpar> Sociéte Béta </areglerpar>
<lignes>
<ligne>
<article> service Alpha </article>
<Prix monnaie="euro"> 2000 </Prix>
</ligne>
<ligne>
<article> service gamma </article>
<Prix monnaie="euro"> 345 </Prix>
</ligne>
</lignes>
<total> Total TTC 2345 </total>
</facture>
Questions :
1. Dessiner un arbre qui montre la structure du document XML ci-dessus.
2. Donner la DTD de ce fichier.
Exercice 3 : XML et DTD
On veut produire un fichier XML permettant de représenter les films d’une cinémathèque. On dispose du cahier des charges suivants :
– une cinémathèque contient des films ;
– chaque film est décrit par son titre, son réalisateur, la date de sa première diffusion,
son genre et le pays de son producteur ;
– la date de diffusion est composée du jour, du mois et de l’année.
Questions :
1. Dresser un arbre montrant la structure du document XML.
2. Quel sera le document XML correspondant au tableau figurant à la fin de l’exercice.
3. Modifier la structure du fichier XML pour qu’un film ne soit décrit que par une seule
balise (il n’est plus composé).
4. Donner les dtd des deux versions du fichier XML de la cinémathèque.
titre
Razzia sur la chnouf
Les tontons flingueurs
Les Barbouzes
réalisateur
Henri Decoin
Georges Lautner
Georges Lautner
date
07/04/1955
27/11/1963
10/12/1964
genre
policier
comédie
comédie
pays
Français
Franco-italo-allemand
Franco-italien
Exercice 4 : XML Schema
Écrire les fichiers XML schema des documents XML produits lors des exercices 1 et 2.
6