From 26c2570680f528525381bb644976e8ae234a3a3c Mon Sep 17 00:00:00 2001 From: Super_JK Date: Sat, 5 Mar 2022 21:48:39 +0100 Subject: [PATCH] initial cpmmit --- .idea/.gitignore | 8 ++++ .idea/TPBDD2.iml | 9 +++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/dictionaries/jika.xml | 3 ++ .idea/discord.xml | 7 ++++ .idea/misc.xml | 9 +++++ .idea/modules.xml | 8 ++++ dtd/biblio.dtd | 14 +++++++ dtd/dico.dtd | 4 ++ dtd/mp.dtd | 6 +++ dtd/personne.dtd | 11 ++++++ dtd/rep.dtd | 6 +++ python/TP1.py | 17 +++++++++ python/TP2.py | 39 ++++++++++++++++++++ python/personne.py | 55 ++++++++++++++++++++++++++++ xml/TP1.xml | 55 ++++++++++++++++++++++++++++ xml/dtd/biblio.xml | 14 +++++++ xml/dtd/dico.xml | 30 +++++++++++++++ xml/dtd/mp.xml | 7 ++++ xml/dtd/personne.xml | 16 ++++++++ xml/dtd/rep.xml | 13 +++++++ xml/schema/dico.xml | 21 +++++++++++ xml/schema/exemple.xml | 27 ++++++++++++++ xml/schema/films.xml | 15 ++++++++ 24 files changed, 399 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/TPBDD2.iml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/dictionaries/jika.xml create mode 100644 .idea/discord.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 dtd/biblio.dtd create mode 100644 dtd/dico.dtd create mode 100644 dtd/mp.dtd create mode 100644 dtd/personne.dtd create mode 100644 dtd/rep.dtd create mode 100755 python/TP1.py create mode 100644 python/TP2.py create mode 100644 python/personne.py create mode 100644 xml/TP1.xml create mode 100644 xml/dtd/biblio.xml create mode 100644 xml/dtd/dico.xml create mode 100644 xml/dtd/mp.xml create mode 100644 xml/dtd/personne.xml create mode 100644 xml/dtd/rep.xml create mode 100644 xml/schema/dico.xml create mode 100644 xml/schema/exemple.xml create mode 100644 xml/schema/films.xml 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