|
1
|
|
|
from lxml import etree |
|
2
|
|
|
|
|
3
|
|
|
from kerapu.shredder.Shredder import Shredder |
|
4
|
1 |
|
|
|
5
|
|
|
|
|
6
|
1 |
|
class BoomBestandenShredder(Shredder): |
|
7
|
|
|
""" |
|
8
|
|
|
Klasse voor het schreden en opslaan in CSV-formaat van boombestanden opgeslagen in XML-formaat. |
|
9
|
1 |
|
""" |
|
10
|
|
|
|
|
11
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
12
|
|
|
def shred_xml_file(self, filename: str) -> None: |
|
13
|
|
|
""" |
|
14
|
|
|
Slaat de boombestanden op in CSV-formaat. |
|
15
|
1 |
|
|
|
16
|
|
|
:param str filename: De filenaam van het XML bestand. |
|
17
|
|
|
""" |
|
18
|
|
|
self._io.title('Shredder') |
|
19
|
|
|
|
|
20
|
|
|
doc = etree.parse(filename) |
|
21
|
1 |
|
|
|
22
|
|
|
xpath = '/soapenv:Envelope/soapenv:Body/InlezenBoomBestanden/BoomBestanden/' |
|
23
|
1 |
|
namespaces = {'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/'} |
|
24
|
|
|
|
|
25
|
1 |
|
# Extract beslis regels. |
|
26
|
1 |
|
table = doc.xpath(xpath + 'BeslisRegels/BeslisRegel', namespaces=namespaces) |
|
27
|
|
|
fields = ['BeslisRegelId', |
|
28
|
|
|
'AttribuutGroepId', |
|
29
|
1 |
|
'BeslisRegelTrue', |
|
30
|
1 |
|
'BeslisRegelFalse', |
|
31
|
|
|
'LabelTrue', |
|
32
|
|
|
'LabelFalse', |
|
33
|
|
|
'IndicatieAanspraakbeperking', |
|
34
|
|
|
'VersieDatum'] |
|
35
|
|
|
self.extract_table(table, 'BeslisRegels.csv', fields, fields) |
|
36
|
|
|
|
|
37
|
|
|
# Extract attribuut groep. |
|
38
|
1 |
|
table = doc.xpath(xpath + 'AttribuutGroepen/AttribuutGroep', namespaces=namespaces) |
|
39
|
|
|
fields = ['AttribuutGroepId', |
|
40
|
|
|
'AttribuutGroepOmschrijving', |
|
41
|
1 |
|
'AantalVoorwaardenVoorTrue', |
|
42
|
1 |
|
'VersieDatum'] |
|
43
|
|
|
self.extract_table(table, 'AttribuutGroepen.csv', fields, fields) |
|
44
|
|
|
|
|
45
|
|
|
# Extract attribuut groep koppeling. |
|
46
|
1 |
|
table = doc.xpath(xpath + 'AttribuutGroepKoppelingen/AttribuutGroepKoppeling', namespaces=namespaces) |
|
47
|
|
|
fields = ['AttribuutGroepKoppelingId', |
|
48
|
|
|
'AttribuutGroepId', |
|
49
|
1 |
|
'AttribuutId', |
|
50
|
1 |
|
'AttribuutToetsWijze', |
|
51
|
|
|
'OnderToetsWaarde', |
|
52
|
|
|
'BovenToetsWaarde', |
|
53
|
|
|
'VersieDatum'] |
|
54
|
|
|
self.extract_table(table, 'AttribuutGroepKoppelingen.csv', fields, fields) |
|
55
|
|
|
|
|
56
|
|
|
# Extract attributen |
|
57
|
1 |
|
table = doc.xpath(xpath + 'Attributen/Attribuut', namespaces=namespaces) |
|
58
|
|
|
fields = ['AttribuutId', |
|
59
|
|
|
'AttribuutOmschrijving', |
|
60
|
1 |
|
'BoomParameterNummer', |
|
61
|
1 |
|
'FilterToetsWijze', |
|
62
|
|
|
'FilterWaardeType', |
|
63
|
|
|
'OnderFilterWaarde', |
|
64
|
|
|
'BovenFilterWaarde', |
|
65
|
|
|
'VersieDatum'] |
|
66
|
|
|
self.extract_table(table, 'Attributen.csv', fields, fields) |
|
67
|
|
|
|
|
68
|
|
|
# Extract boomparameters. |
|
69
|
1 |
|
table = doc.xpath(xpath + 'BoomParameters/BoomParameter', namespaces=namespaces) |
|
70
|
|
|
fields = ['BoomParameterNummer', |
|
71
|
|
|
'Omschrijving', |
|
72
|
1 |
|
'TabelNaam', |
|
73
|
1 |
|
'VeldNaam'] |
|
74
|
|
|
self.extract_table(table, 'BoomParameters.csv', fields, fields) |
|
75
|
|
|
|
|
76
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
77
|
|
|
|