Listing [Python.Docs]: xml.etree.ElementTree - The ElementTree XML API.
Considering this exact XML blob, there are 2 errors in your code:
The root node is Product node, so if you search for (other) Product sub-nodes it won't find anything
releaseDate is an attribute (not a tag) so it doesn't belong in the path
Here''s an example.
blob.xml
<?xml version="1.0" encoding="UTF-8"?>
<Product prodID="bed" lang="en">
<ProductState stateType="Published" stateDateTime="2019-04" testDate="2019-04" releaseDate="2019"/>
<!-- Other nodes -->
</Product>
code00.py:
#!/usr/bin/env python
import sys
import xml.etree.ElementTree as ET
def main(*argv):
xmlfile = "./blob.xml"
root = ET.parse(xmlfile).getroot()
print("Root node:", root)
for product_state_node in root.findall("ProductState"):
print("Release date: ", product_state_node.attrib.get("releaseDate"))
if __name__ == "__main__":
print("Python {:s} {:03d}bit on {:s}\n".format(" ".join(elem.strip() for elem in sys.version.split("\n")),
64 if sys.maxsize > 0x100000000 else 32, sys.platform))
rc = main(*sys.argv[1:])
print("\nDone.\n")
sys.exit(rc)
Output:
[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q074401612]> "e:\Work\Dev\VEnvs\py_pc064_03.09_test0\Scripts\python.exe" ./code00.py
Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] 064bit on win32
Root node: <Element 'Product' at 0x0000020698C4A860>
Release date: 2019
Done.
Although for this simple example it's might not be the case I prefer XPath when iterating XML trees. For more details you could check (there are many more):