-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlutil.py
More file actions
32 lines (27 loc) · 976 Bytes
/
Copy pathxmlutil.py
File metadata and controls
32 lines (27 loc) · 976 Bytes
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
#!/usr/bin/env python3
import logging
import os
import subprocess
import sys
def parse_xml_tag(element, tagName, required=False):
"""Helper function to analyse a xml tag."""
if element.find(tagName) is not None:
if element.find(tagName).text is not None:
return element.find(tagName).text
if required:
raise Exception(f'Required tag missing: {tagName}')
return None
def parse_xml_tag_list(element, tagName):
"""Helper function to analyse a xml tag which can be occure several times."""
items = list()
tags = element.findall(tagName)
for tagName in tags:
items.append(tagName.text)
return items
def parse_xml_attrib(element, attrName, required=False, default=None):
"""Helper function to analyse a xml attribute."""
if attrName in element.attrib:
return element.attrib[attrName]
if required:
raise Exception(f'Required attribute missing: {attrName}')
return default