-
Notifications
You must be signed in to change notification settings - Fork 0
/
L05C02.py
31 lines (24 loc) · 922 Bytes
/
L05C02.py
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
#
# Generate a valid xml file at /tmp/vulnerable-countries.xml.
# It should contain a list of country nodes attached to a root node.
# Each country node should have a name attribute.
# The third node name should be Panama.
#
import xml.etree.ElementTree as ET
def generate_xml():
# Create the root element
root = ET.Element("countries")
# List of countries
countries = ["USA", "Canada", "Panama", "Germany", "Japan"]
# Create country nodes and add them to the root
for country_name in countries:
country_node = ET.SubElement(root, "country")
country_node.set("name", country_name)
# Create the ElementTree object
tree = ET.ElementTree(root)
# Save the XML file to /tmp/vulnerable-countries.xml
file_path = "/tmp/vulnerable-countries.xml"
tree.write(file_path)
print(f"XML file generated at: {file_path}")
if __name__ == "__main__":
generate_xml()