Source code for python_utils.xml_parser
#!/usr/bin/env python3
import xml.etree.ElementTree as ET
[docs]def load_xml_file(xml_file):
"""Loads xml file
Args:
xml_file: path to xml file
Returns:
root of the xml tree
"""
tree = ET.parse(xml_file)
return tree
[docs]def has_tag_with_value(tree, tag, value):
"""Check if xml tree has a node with tag and value
Args:
tree: the xml tree
tag: the tag
value: text of tag
Returns:
Boolean
"""
for node in tree.iter():
if node.tag == tag and node.text == value:
return True
return False