40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
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())
|