I have an XML file with an element which looks like this:
<wrapping_element>
<prefix:tag xmlns:prefix="url">value</prefix:tag>
</wrapping_element>
I want to get this element, so I am using lxml as follows:
wrapping_element.find('prefix:tag', wrapping_element.nsmap)
but I get the following error: SyntaxError: prefix 'prefix' not found in prefix map because prefix is not defined before reaching this element in the XML.
Is there a way to get the element anyway?
findin the documentation labyrinth, but there seems to be a methodxpathtoo, maybe you can use it.xpathrequires anamespacesargument asfinddoes. My problem is that I can't find a way to retrieve the namespace without the element nor the element without the namespace.wrapping_element.xpath('/*/*[local-name()="tag"]')?wrapping_element.xpath('./*[local-name()="tag"]'), it's working perfectly. Thanks a lot!