I know that there are a few examples already of retrieving specific attributes from XML nodes, but I've not been successful in doing so with a namespace. I am able to retrieve an attribute without any namespaces, such as in this example.
Suppose I have the following "example.wsdl" file:
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Name of the file">
<wsdl:documentation>Documentation of the file</wsdl:documentation>
</wsdl:definitions>
I'd like to retrieve the "name" attribute of the node "wsdl:defintions" I have tried doing the below:
from lxml import etree
tree = etree.parse("example.wsdl")
rootWSDL = tree.getroot()
print(tree.find('./wsdl:definitions', rootWSDL.nsmap).attrib['name'])
However, the above returns an empty list with the following message:
AttributeError: 'NoneType' object has no attribute 'attrib'
For what it's worth, the Python version I am using is 3.7.5