I have Googled my pants off to no avail. What I am trying to do is very simple: I'd like to access the UniqueID value in the following XML contained in a string using ElementTree.
from xml.etree.ElementTree import fromstring
xml_string = """<ListObjectsResponse xmlns='http://www.example.com/dir/'>
<Item>
<UniqueID>abcdefghijklmnopqrstuvwxyz0123456789</UniqueID>
</Item>
</ListObjectsResponse>"""
NS = "http://www.example.com/dir/"
tree = fromstring(xml_string)
I know that I should use the fromstring
method to parse the XML string, but I can't seem to identify how to access the UniqueID. I'm not certain how to use the find
, findall
, or findtext
methods with respect to the namespace.
Any help is totally appreciated.