1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #! /usr/bin/python3
# -*- coding: UTF-8 -*-
import xml.etree.ElementTree as ET
def _pretty_print(current, parent=None, index=-1, depth=0):
for i, node in enumerate(current):
_pretty_print(node, current, i, depth + 1)
if parent is not None:
if index == 0:
parent.text = '\n' + ('\t' * depth)
else:
parent[index - 1].tail = '\n' + ('\t' * depth)
if index == len(parent) - 1:
current.tail = '\n' + ('\t' * (depth - 1))
liste_Stations = ['URDF', 'VALF']
stationsXML = './xml/stations_FR.old2'
xml = ET.parse(stationsXML)
stations = xml.getroot()
for sta in liste_Stations:
newSta = ET.SubElement(stations, 'station')
newSta.attrib['id'] = sta
newEvt = ET.SubElement(newSta, 'evt')
newEvt.attrib['class'] = 'local'
newTrace = ET.SubElement(newEvt, 'trace')
temp = {
'class' : 'local',
'lat' : '0',
'lon' : '0',
}
newEvt.attrib = temp
_pretty_print(stations)
print(ET.tostring(stations)) |
Partager