commit 26c2570680f528525381bb644976e8ae234a3a3c Author: Super_JK Date: Sat Mar 5 21:48:39 2022 +0100 initial cpmmit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/TPBDD2.iml b/.idea/TPBDD2.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/TPBDD2.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/dictionaries/jika.xml b/.idea/dictionaries/jika.xml new file mode 100644 index 0000000..d7b9ea2 --- /dev/null +++ b/.idea/dictionaries/jika.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..30bab2a --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3392c25 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..eaa50a0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dtd/biblio.dtd b/dtd/biblio.dtd new file mode 100644 index 0000000..a4c0cd3 --- /dev/null +++ b/dtd/biblio.dtd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dtd/dico.dtd b/dtd/dico.dtd new file mode 100644 index 0000000..22c960a --- /dev/null +++ b/dtd/dico.dtd @@ -0,0 +1,4 @@ + + + + diff --git a/dtd/mp.dtd b/dtd/mp.dtd new file mode 100644 index 0000000..ce1ab00 --- /dev/null +++ b/dtd/mp.dtd @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dtd/personne.dtd b/dtd/personne.dtd new file mode 100644 index 0000000..77e9737 --- /dev/null +++ b/dtd/personne.dtd @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/dtd/rep.dtd b/dtd/rep.dtd new file mode 100644 index 0000000..cbf2401 --- /dev/null +++ b/dtd/rep.dtd @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/python/TP1.py b/python/TP1.py new file mode 100755 index 0000000..4ba17d0 --- /dev/null +++ b/python/TP1.py @@ -0,0 +1,17 @@ +from xml.dom import minidom +doc = minidom.parse('../xml/TP1.xml') + +print(doc.getElementsByTagName('Q1')[0].toxml()) # Représentation textuelle du sous-arbre +print(doc.getElementsByTagName('personne')[0].getAttribute('nom')) +print(doc.getElementsByTagName('personne')[0].getAttribute('prenom')) + +print(doc.getElementsByTagName('personne')[0].childNodes) + +print(doc.getElementsByTagName('personne')[0].childNodes[1].firstChild.data) +print(doc.getElementsByTagName('personne')[0].childNodes[3].firstChild.data) +print(doc.getElementsByTagName('personne')[0].childNodes[3].getAttribute('code')) + + +#print(doc.getElementsByTagName('sfq')) +#print(doc.getElementsByTagName('telephone').data) + diff --git a/python/TP2.py b/python/TP2.py new file mode 100644 index 0000000..b89cbbe --- /dev/null +++ b/python/TP2.py @@ -0,0 +1,39 @@ +from os import listdir +from os.path import isdir, isfile +from xml.dom import minidom + +doc = minidom.parse('../xml/TP1.xml') +dico = doc.getElementsByTagName('dictionary')[0] + + +def printDico(dico, past): + for child in dico.childNodes: + if child.nodeType == child.ELEMENT_NODE: + val = child.getAttribute('value') + if len(child.childNodes) == 0: + print(past + val) + else: + printDico(child, past + val + "-") + + +# printDico(dico,'') + +def dirToXml(path, doc, el): + for elem in listdir(path): + path_ = path + "/" + elem + if isfile(path_): + node = doc.createElement("file") + node.attributes["name"] = elem + el.appendChild(node) + elif isdir(path_): + node = doc.createElement("dir") + node.attributes["name"] = elem + el.appendChild(node) + dirToXml(path_, doc, node) + + +root = minidom.Document() +xml = root.createElement('root') +root.appendChild(xml) +dirToXml("/", root, root.getElementsByTagName("root")[0]) +print(root.toprettyxml()) diff --git a/python/personne.py b/python/personne.py new file mode 100644 index 0000000..63b05e2 --- /dev/null +++ b/python/personne.py @@ -0,0 +1,55 @@ +from xml.dom import minidom +doc = minidom.parse('../xml/TP1.xml') + +# Affiche l'arbre complet +#print(doc.toxml()) +# Ou +#print(doc.toprettyxml()) + +# On récupère le noeud personne. +personne = doc.getElementsByTagName('personne')[0] + + +def getChildrenByTagName(doc, name): + """Une fonction récupérant les fils directs d'un certain type.""" + return [c for c in doc.childNodes + if c.nodeType == c.ELEMENT_NODE and c.tagName == name] + + +#personne = getChildrenByTagName(doc, 'personne')[0] + +# Affiche le nom et le prenom de la personne +print(personne.getAttribute('nom'), personne.getAttribute('prenom')) +# Ou +print(personne.attributes['nom'].value, personne.attributes['prenom'].value) + +# Affiche l'adresse email +email = doc.getElementsByTagName('email')[0] +email = getChildrenByTagName(personne, 'email')[0] +print(email.firstChild.data) + +# Affiche l'adresse postale ainsi que le code postal +adresse = personne.getElementsByTagName('adresse')[0] +print(adresse.firstChild.data, adresse.getAttribute('code')) + +# Acceder à un element inexistant +print(doc.getElementsByTagName('test')) +# Afficher le contenu de l'attribut data du telephone +# personne.getElementsByTagName('phone')[0].data + +# Lister les methodes du noeud fils de email +print(dir(email.firstChild)) + +# Compter le nombre d'elements du noeud racine +print(len(doc.childNodes)) +print(doc.childNodes) + +print(doc.toxml()) + +# Modifier l'email et afficher le résultat +email.firstChild.data = "foo@bar.com" +print(doc.toxml()) + +# Modifier son numero de telephone +doc.getElementsByTagName('telephone')[0].attributes['numero'].value = '42' +print(doc.toxml()) diff --git a/xml/TP1.xml b/xml/TP1.xml new file mode 100644 index 0000000..2c94f52 --- /dev/null +++ b/xml/TP1.xml @@ -0,0 +1,55 @@ + + + + + qsdf + ddf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xml/dtd/biblio.xml b/xml/dtd/biblio.xml new file mode 100644 index 0000000..abe8be6 --- /dev/null +++ b/xml/dtd/biblio.xml @@ -0,0 +1,14 @@ + + + + + sdf + + + + +
+ +
+ +
\ No newline at end of file diff --git a/xml/dtd/dico.xml b/xml/dtd/dico.xml new file mode 100644 index 0000000..b6d30c1 --- /dev/null +++ b/xml/dtd/dico.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xml/dtd/mp.xml b/xml/dtd/mp.xml new file mode 100644 index 0000000..1f2b1ae --- /dev/null +++ b/xml/dtd/mp.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/xml/dtd/personne.xml b/xml/dtd/personne.xml new file mode 100644 index 0000000..4383887 --- /dev/null +++ b/xml/dtd/personne.xml @@ -0,0 +1,16 @@ + + + + + qsdf + SFGV + ddf + + + + + ztgh + uyk + qsdf + + diff --git a/xml/dtd/rep.xml b/xml/dtd/rep.xml new file mode 100644 index 0000000..b40116a --- /dev/null +++ b/xml/dtd/rep.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/xml/schema/dico.xml b/xml/schema/dico.xml new file mode 100644 index 0000000..d395b63 --- /dev/null +++ b/xml/schema/dico.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xml/schema/exemple.xml b/xml/schema/exemple.xml new file mode 100644 index 0000000..2cdc3f7 --- /dev/null +++ b/xml/schema/exemple.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xml/schema/films.xml b/xml/schema/films.xml new file mode 100644 index 0000000..f30720d --- /dev/null +++ b/xml/schema/films.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + Ian Charleson \ No newline at end of file