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 (hoock@lisic.univ-littoral.fr) Exercice 1 : XML Les documents XML suivants sont-ils corrects? Trouvez et corrigez les éventuels erreurs. 1. 1: <?xml version="1.0" encoding="utf-8"?> 2: <!DOCTYPE html [ 3: <!ELEMENT html (head,body)> 4: <!ELEMENT head (title)> 6: <!ELEMENT body (p+)> 7: <!ELEMENT p (#PCDATA)> 8: ]> 9: <html> 10: <head><title>hello, World</title></head> 11: <body><p>hello, World</p></body> 12: </html> 2. 1: <?xml version="1.0" encoding="utf-8"?> 2: <p>this is a test. This is a test of the <em> 3: <strong>emergency</em> Broadcast System.</strong></p> 3. 1: <?xml version="1.0" encoding="utf-8"?> 2: <!DOCTYPE note [ 3: <!ELEMENT note (Message)> 4: <!ELEMENT Message (to,from,heading,body)> 5: <!ELEMENT to (#PCDATA)> 6: <!ELEMENT from (#PCDATA)> 7: <!ELEMENT heading (#PCDATA)> 8: <!ELEMENT body (#PCDATA)> 9: <!ATTLIST note date CDATA #REQUIRED> 10: ]> 11: <note date="12/11/2007"> 12: <!-- This is a comment --> 13: <Message><to>Tove</to> 14: <from>jani</from> 15: <heading>reminder</heading> 16: <body>don t forget me this weekend!</body></message> 17: </note> 18: <note date="13/11/2007"> 1
19: <message><to>jani</to> 20: <from>tove</from> 21: <heading>re: Reminder</heading> 22: <body>ok!</body></message> 23: </note> 4. 1: <?xml version="1.0" encoding="utf-8"?> 2: <xs:schema attributeformdefault="unqualified" 3: xmlns:xs="http://www.w3.org/2001/xmlschema"> 4: <xs:element name="points"> 5: <xs:complextype> 6: <xs:sequence> 7: <xs:element maxoccurs="unbounded" name="point"> 8: <xs:complextype> 9: <xs:attribute name="x" type="xs:unsignedshort" use="required"/> 10: <xs:attribute name="y" type="xs:unsignedshort" use="required"/> 11: </xs:complextype> 12: </xs:element> 13: </xs:sequence> 14: </xs:complextype> 15: </xs:element> 16: </xs:schema> 5. 1: <?xml version="1.0" encoding="utf-8"?> 2: <!DOCTYPE html [ 3: <!ELEMENT html (head,body)> 4: <!ELEMENT head (title)> 6: <!ELEMENT body (p+)> 7: <!ELEMENT p (#PCDATA)> 8: ]> 9: <html> 10: <head><title>paragraphs</title></head> 11: <body><p>this is a paragraph.<br/> 12: <p>this is another paragraph.<br/> 13: <p>third paragraph.</body> 14: </html> 6. 1: <?xml version="1.0" encoding="utf-8"?> 2: <rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 3: xmlns:dc="http://purl.org/dc/elements/1.1/"> 4: <rdf:description rdf:about=http://www.acronymfinder.com/> 5: <dc:title>acronym Finder</dc:title> 6: <dc:description>the Acronym Finder is a world wide 7: web (WWW) searchable database of more than 169,000 8: abbreviations and acronyms about computers, 9: technology, telecommunications, and military 10: acronyms and abbreviations.</dc:description> 11: <dc:subject> 12: <rdf:bag> 2
13: <rdf:li>astronomy</rdf:li> 14: <rdf:li>literature</rdf:li> 15: <rdf:li>mathematics</rdf:li> 16: <rdf:li>music</rdf:li> 17: <rdf:li>philosophy</rdf:li> 18: </rdf:bag> 19: </dc:subject> 20: </rdf:description> 21: </rdf:rdf> 7. 1: <?xml version="1.0" encoding="utf-8"?> 2: <!DOCTYPE html [ 3: <!ELEMENT html (head,body)> 4: <!ELEMENT head (title)> 6: <!ELEMENT body (p b i br)+> 7: <!ELEMENT p (b i)+> 8: <!ELEMENT br EMPTY> 9: <!ELEMENT b (#PCDATA i)*> 10: <!ELEMENT i (#PCDATA b)*> 11: ]> 12: <html><body> 13: <p><b><i>this paragraph is bold and italic.</b></i></p><br/> 14: <p><i><b>this paragraph is italic and bold.</i></b></p><br/> 15: </body></html> 8. 1: <?xml version="1.0" encoding="utf-8"?> 2: <!DOCTYPE catalog [ 3: <!ELEMENT catalog (work)> 4: <!ELEMENT work (title,author)> 6: <!ELEMENT author (#PCDATA)> 7: <!ATTLIST work type CDATA #REQUIRED> 8: <!ATTLIST work date CDATA #REQUIRED> 9: ]> 10: <catalog> 11: <work date= 1906 type="prose"> 12: <title>the Gift Of The Magi</title> 13: <author>o. Henry</author> 14: </work> 15: <work type= poem > 16: <title>the Raven</title> 17: <author>edgar Allen Poe</author> 18: </work> 19: <work type= play date= 1601 > 20: <author>william Shakespeare</author> 21: <title>hamlet</title> 22: </work> 23: </catalog> 3
9. 1: <?xml version="1.0" encoding="utf-8"?> 2: <letter> 3: <date>december 11, 2002</date> 4: <addressee> 5: <name>melvile Dewey</name> 6: <address_one> 7: Columbia University</address_one><address_two>New York, NY 8: </address_two> 9: </addressee> 10: <greeting>dear Melvile,</greeting> 11: <paragraph>i have been reading your ideas concerning nature of 12: librarianship, and <italics>i find them very intriguing</italics>. 13: I would love the opportunity to discuss with you...</paragraph> 14: <list><item>monday, 2-4</item> 15: <item>tuesday, 3-5</item> 16: <item>thursday, 1-3</item> 17: </list> 18: <paragraph>we hope you can join us.</paragraph> 19: <closing>sincerely, S. R. Ranganathan</closing> 20: </letter> 10. 1: <?xml version="1.0"?> 2: <!DOCTYPE dictionary [ 3: <!ELEMENT dictionary (word*)> 4: <!ELEMENT word (update name description definition)*> 5: <!ELEMENT update EMPTY> 6: <!ATTLIST update date CDATA #REQUIRED> 7: <!ELEMENT name (#PCDATA)> 8: <!ATTLIST name is_acronym CDATA #IMPLIED > 9: <!ELEMENT description (#PCDATA)> 10: <!ELEMENT definition (#PCDATA)> 11: ]> 12: <dictionary> 13: <word> 14: <update date="2002-12-23"/> 15: <name is_acronym="true">xml</name> 16: <description>extensible Markup Language</description> 17: </word> 18: <word> 19: <update date="2002-12-23"/> 20: <name is_acronym="true">pop</name> 21: <definition default>post Office Protocol</definition> 22: <definition>point Of Purchase</definition> 23: </dictionary> 11. 1: <?xml version="1.0" encoding="utf-8"?> 2: <domain type= kvm> 3: <name>domain</name>< 4: <memory>524288</memory> 5: <vcpu>2</vcpu> 4
6: <features><acpi/><pae/> 7: <clock offset= utc > 8: <disk type= block device= cdrom > 9: <driver name= qemu type= raw /> 10: <source file= /path/to/image.iso /> 11: <tar get dev= hdc bus= ide /> 12: <readonly/></name> 13: </disk> 14: </domain> 12. 1: <?xml version="1.0" encoding="utf-8"?> 2: <name>oyster Soup</name> 3: <author>eric Lease Morgan</author> 4: <copyright holder=eric Lease Morgan> 2003</copyright> 5: <ingredients> 6: <list> 7: <item>1 stalk of celery 8: <item>1 onion 9: <item>2 tablespoons of butter 10: <item>2 cups of oysters and their liquor 11: <item>2 cups of half & half 12: </list><cost>total cost < 36 euro </cost> 13: </ingredients> 14: <process><p>begin by sauteing the celery and onions in butter until 15: soft. 16: Add oysters, oyster liquor, and cream. Heat until the oysters float. 17: Serve in warm bowls.</p> 18: <p><i>yummy!</p></i> 19: </process> 13. 1: <?xml version="1.0" encoding="utf-8"?> 2: <!DOCTYPE list [ 3: <!ELEMENT list (list integer)*> 4: <!ELEMENT integer (#PCDATA)> 5: <!ATTLIST list list CDATA #IMPLIED> 6: ]> 7: <list> 8: <integer>3</integer> 9: <list list="list of lists of integers"> 10: <list> 11: <integer>4</integer> 12: <integer>9</integer> 13: </list> 14: </list> 15: <integer>13</integer> 16: <list/> 17: </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 réalisateur date genre pays Razzia sur la chnouf Henri Decoin 07/04/1955 policier Français Les tontons flingueurs Georges Lautner 27/11/1963 comédie Franco-italo-allemand Les Barbouzes Georges Lautner 10/12/1964 comédie Franco-italien Exercice 4 : XML Schema Écrire les fichiers XML schema des documents XML produits lors des exercices 1 et 2. 6