Corrections des travaux pratiques sur XML
Modélisation et documents XML
Éléments de correction pour les exercices de modélisation.
Les articles
- la DTD Article : voir, récupérer ;
 - la feuille de style CSS : voir, récupérer ;
 - le document XML : voir, récupérer ;
 
Les brèves
Le championnat de football
Les acteurs de cinéma
Les films de cinéma
Les bandes dessinées de Florent
- la DTD : voir, récupérer ;
 - le XML Schéma : voir, récupérer ;
 - le Relax NG : voir, récupérer ;
 - le document XML : voir, récupérer ;
 
La CDthèque
Requêtes XPath
Éléments de correction pour les exercices sur XPath.
Les articles
- 
/ ou pour l'élément racine : /child::* /*
 - 
/descendant::node() //node() ou à partir de l'élément racine : /child::*/descendant::node() /*//node()
 - 
/descendant::*/attribute::* //@*
 - 
/descendant::text() //text()
 - 
/descendant::processing-instruction() //processing-instruction()
 - 
/descendant::processing-instruction('xml-stylesheet') //processing-instruction('xml-stylesheet') - 
/descendant::p/child::text() //p/text()
 - 
/descendant::p[child::important] //p[important]
 - 
/descendant::référence[attribute::code='siteMarc'] //référence[@code='siteMarc']
 - 
/descendant::*/child::auteur[position()=2] //*/auteur[2] /descendant::auteur[count(preceding::auteur)=1] //auteur[count(preceding::auteur)=1] /descendant::auteur[(preceding::auteur) and not(preceding::auteur/preceding::auteur)] //auteur[(preceding::auteur) and not(preceding::auteur/preceding::auteur)]
 
Les acteurs de cinéma
- 
/child::liste_acteurs/child::acteur /liste_acteurs/acteur /descendant::acteur //acteur
 - 
count(/child::liste_acteurs/child::acteur) count(/liste_acteurs/acteur) count(/descendant::acteur) count(//acteur)
 - 
/descendant::comment() //comment()
 - 
/descendant::comment()[position()=2] //comment()[2] NON !!! - 
/descendant::acteur[position()=1]/node()[position()=1] //acteur[1]/node()[1]
 - 
/descendant::acteur[position()=2]/node()[position()=1] //acteur[2]/node()[1]
 - 
/descendant::acteur/*[position()=1 or position()=2] //acteur/*[position()<=2]
 - 
/descendant::acteur/*[position()=last()] //acteur/*[last()]
 - 
/descendant::acteur[attribute::id='clint'] //acteur[@id='clint']
 - 
/descendant::acteur[child::prenom/text()='Clint'] //acteur[prenom='Clint']
 - 
/descendant::acteur/child::biographie/child::p[last()=2]/parent::biographie/parent::acteur/child::nom/text() //acteur/biographie/p[last()=2]/../../nom/text() /descendant::acteur/child::biographie/child::p[last()=2]/ancestor::acteur/child::nom/text() /descendant::acteur/child::nom/child::text()[count(ancestor::acteur/child::biographie/child::p)=2] //acteur/nom/text()[count(../../biographie/p)=2]
 
Le championnat de football
- 
/descendant::JOURNEE[attribute::NUMERO < 8] //JOURNEE[@NUMERO < 8] /descendant::JOURNEE[attribute::NUMERO=8]/preceding-sibling::JOURNEE //JOURNEE[@NUMERO=8]/preceding-sibling::JOURNEE
 - 
/descendant::JOURNEE[attribute::NUMERO=4]/child::RENCONTRE //JOURNEE[@NUMERO=4]/RENCONTRE
 - 
/descendant::JOURNEE/child::RENCONTRE[position()=1] //JOURNEE/RENCONTRE[1]
 - 
/descendant::JOURNEE[attribute::NUMERO=10]/child::RENCONTRE[attribute::DOMICILE='Bastia']/attribute::EXTERIEUR | /descendant::JOURNEE[attribute::NUMERO=10]/child::RENCONTRE[attribute::EXTERIEUR='Bastia']/attribute::DOMICILE //JOURNEE[@NUMERO=10]/RENCONTRE[@DOMICILE='Bastia']/@EXTERIEUR | //JOURNEE[@NUMERO=10]/RENCONTRE[@EXTERIEUR='Bastia']/@DOMICILE
 - 
/descendant::RENCONTRE[attribute::DOMICILE='Bastia']/attribute::EXTERIEUR | /descendant::RENCONTRE[attribute::EXTERIEUR='Bastia']/attribute::DOMICILE //RENCONTRE[@DOMICILE='Bastia']/@EXTERIEUR | //RENCONTRE[@EXTERIEUR='Bastia']/@DOMICILE
 - 
/descendant::RENCONTRE[attribute::SCORED='-'] //RENCONTRE[@SCORED='-']
 - 
/descendant::RENCONTRE[attribute::DOMICILE='Bastia' and attribute::SCORED!='-' and attribute::SCORED=attribute::SCOREE] //RENCONTRE[@DOMICILE='Bastia' and @SCORED!='-' and @SCORED=@SCOREE] - 
count(/descendant::RENCONTRE[attribute::SCORED!='-' and attribute::SCORED=attribute::SCOREE]) count(//RENCONTRE[@SCORED!='-' and @SCORED=@SCOREE]) 100 .* count(/descendant::RENCONTRE[attribute::SCORED!='-' and attribute::SCORED=attribute::SCOREE]) div count(/descendant::RENCONTRE[attribute::SCORED!='-']) 100*count(//RENCONTRE[@SCORED!='-' and @SCORED=@SCOREE]) div count(//RENCONTRE[@SCORED!='-'])
 - 
count(/descendant::RENCONTRE[attribute::SCORED>attribute::SCOREE]) count(//RENCONTRE[@SCORED>@SCOREE]) 100 * count(/descendant::RENCONTRE[attribute::SCORED>attribute::SCOREE]) div count(/descendant::RENCONTRE[attribute::SCORED!='-']) 100*count(//RENCONTRE[@SCORED>@SCOREE]) div count(//RENCONTRE[@SCORED!='-'])
 - 
count(/descendant::RENCONTRE[attribute::SCORED<attribute::SCOREE]) count(//RENCONTRE[@SCORED<@SCOREE]) 100 * count(/descendant::RENCONTRE[attribute::SCORED<attribute::SCOREE]) div count(/descendant::RENCONTRE[attribute::SCORED!='-']) 100*count(//RENCONTRE[@SCORED<@SCOREE]) div count(//RENCONTRE[@SCORED!='-'])
 
Les brèves
Correction fournie par Grégoire Laurence, merci à lui !
- 
/descendant-or-self::node() //node() Il en manque, non ? - 
/descendant::* //*
 -  
soit uniquement les attributs href :
/descendant::*/attribute::href //@href
soit tous les attributs dont le contenu commence par http :
/descendant::*/attribute::*[starts-with (self::node(),'http')] //@*[starts-with (.,'http')]
 - 
count(/descendant::breve) count(//breve)
 - 
/descendant::breve/child::titre/child::text() //breve/titre/text()
 - 
/descendant::breve[attribute::theme="sport"] //breve[@theme="sport"]
 - 
/descendant::breve[child::photo] //breve[photo]
 - 
/descendant::breve[starts-with(child::titre/child::text(),"D")] //breve[starts-with(titre/text(),"D")]
 - 
/descendant::breve[contains(child::texte/child::text(),"marathon")] //breve[contains(texte/text(),"marathon")]
 - 
/descendant::breve[attribute::theme="actu"]/following::* //breve[@theme="actu"]/following::*
 
Les films
Correction fournie par Grégoire Laurence, merci à lui !
- 
count(/descendant::film) count(//film)
 - 
/descendant::comment() //comment()
 - 
/child::films/child::film[position()=2]/child::casting/child::acteur //film[2]//acteur
 - 
/descendant::film[attribute::lang="en"]/child::titre/child::text() //film[@lang="en"]/titre/text()
 - 
/descendant::acteur[attribute::id="lukemonfils"]/attribute::personnage //acteur[@id="lukemonfils"]/@personnage
 - 
/descendant::film[child::annee="1981"]/child::titre/child::text() //film[annee/text()="1981"]/titre/text()
 - 
count(/descendant::perso[attribute::ref="indy"]) count(//perso[@ref="indy"])
 - 
/descendant::film[count(child::casting/child::acteur)=0] //film[count(.//acteur)=0]
 - 
/descendant::film[contains(child::realisateur,",")] //film[contains(realisateur,",")] mauvaise DTD ? - 
/descendant::film[contains(child::synopsis,"believe")] //film[contains(synopsis,"believe")]
 
Les TODO list
- 
/descendant::*/attribute::* //@*
 - 
/descendant-or-self::comment() //comment()
 - 
/descendant-or-self::text() //text()
 - 
/descendant::*[attribute::deadline][position()=2]/attribute::deadline //*[@deadline][2]/@deadline
 - 
/descendant::item[position()=1] -
 - 
/descendant::items/child::item[position()=1] //item[1]
 - 
/descendant::item[attribute::level='critic']/parent::items/parent::todo/child::title/text() //todo[.//@level='critic']/title/text()
 - 
/descendant::todo[not(child::commentaires)]/child::title/child::text() //todo[not(.//commentaires)]/title/text()
 - 
/descendant::*/attribute::url .//@url
 - 
count(/descendant::todo[position()=2]/child::commentaires/child::par) count(//todo[2]/commentaires/par)
 - 
/descendant::todo[attribute::illustration='sapin.jpg']/child::title/child::text() //todo[@illustration='sapin.jpg']/title/text()
 
Les bandes dessinées
Correction fournie par Grégoire Laurence, merci à lui !
- 
count(/child::bdtheque/child::collection/descendant::bd) count(//collection//bd)
 - 
/child::bdtheque/child::collection/child::bd //bd[not(ancestor::serie)]
 - 
/descendant::titreserie //titreserie
et si titreserie n'était pas propre aux séries :
/descendant::serie/child::titreserie //serie/titreserie
 - 
count(/descendant::serie[child::titreserie/child::text()="Lanfeust de Troy"]/child::bd) count(//serie[titreserie/text()="Lanfeust de Troy"]/bd)
 - 
/descendant::*/attribute::illustration //@illustration
 - 
/descendant::bd[child::illustrateur/attribute::ref=/descendant::personne[child::nom="Larcenet" and child::prenom="Manu"]/attribute::id] //bd[illustrateur/@ref=//personne[nom="Larcenet" and prenom="Manu"]/@id]explication : d'abord on cherche l'identifiant de "Manu Larcenet" //personne[nom="Larcenet" and prenom="Manu"]/@id et ensuite on cherche les bd référençant cet illustrateur... en plus simple si l'on connait déjà l'identifiant :
/descendant::bd[child::illustrateur/attribute::ref="Larcenet"] //bd[illustrateur/@ref="Larcenet"]
 - 
/descendant::personne[child::prenom="Riad"]/attribute::id //personne[prenom="Riad"]/@id
 - 
/descendant::personne[child::nom="Larcenet" and child::prenom="Manu"]/preceding-sibling::* //personne[nom="Larcenet" and prenom="Manu"]/preceding-sibling::*
les autres personnes définies étant des frères de l'élément sélectionné ; ou pour être plus prudent :
/descendant::personne[child::nom="Larcenet" and child::prenom="Manu"]/preceding-sibling::personne //personne[nom="Larcenet" and prenom="Manu"]/preceding::personne
 - 
/descendant::bd[starts-with(child::titre,"L")]/child::sortie/child::text() //bd[starts-with(titre,"L")]/sortie/text()
 - 
/descendant::bd[contains(child::resume,"oiseau")] //bd[contains(resume,"oiseau")]
 - 
/descendant-or-self::bd[position()=2] /descendant-or-self::bd[2] attention ! différent de //bd[2]. 
Transformations XSLT
Éléments de correction pour les exercices sur le langage XSLT.
Les brèves
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - la feuille CSS associée à la page HTML : voir, récupérer ;
 - le résultat final.
 
Le championnat de football
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - la feuille XSLT produisant du SVG : voir, récupérer ;
 - la feuille CSS associée à la page HTML : voir, récupérer ;
 - le résultat final :
- voir le code SVG produit ;
 - la page HTML résultat.
 
 
Les acteurs de cinéma
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - la feuille CSS associée à la page HTML : voir, récupérer ;
 - le résultat final.
 
Les films de cinéma
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - la feuille CSS associée à la page HTML : voir, récupérer ;
 - le résultat final.
 
Les sujets abordés dans une formation
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - le résultat final.
 
Transformation des TODO list
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - le résultat final.
 
Les sujets abordés dans une formation (épisode 2, le retour)
Tourner les tables
Coloration syntaxique d'un fichier XML
- la feuille XSLT produisant du HTML : voir, récupérer ;
 - la feuille CSS associée à la page HTML : voir, récupérer ;
 - application aux acteurs, aux brèves, aux foot, aux films et à elle-même.
 
Calcul de la fonction factorielle
- le fichier XML en entrée : voir, récupérer ;
 - la feuille XSLT réalisant le calcul : voir, récupérer ;
 
Résolution des tours de Hanoï
- le fichier XML en entrée : voir, récupérer ;
 - la feuille XSLT réalisant le calcul : voir, récupérer ;
 
Tester la conjecture de Syracuse
Python et XML : API SAX et DOM
Éléments de correction pour les exercices XML en Python.
Le championnat de football
- le programme Python/SAX calculant les statistiques et produisant le HTML : voir, récupérer ;
 - la feuille CSS associée à la page html : voir, récupérer ;
 - le résultat final.
 
Les acteurs
- le programme Python/SAX qui produit du HTML à partir du fichier d'acteurs : voir, récupérer ;
 - la feuille CSS associée à la page html : voir, récupérer ;
 - le résultat final.
 
Extraction de méta-données
Le programme Python/DOM : voir, récupérer.
Fonctions utiles
Le programme Python/DOM : voir, récupérer.
