how to set namespace prefixes in xml.etree
Question
I wish to set the namespace prefix in xml.etree. I found register_namespace(prefix, url) on the Web but this threw "unknown attribute". I have also tried nsmap=NSMAP but this also fails. I'd be grateful for example syntax that shows how to add specified namespace prefixes
Solution
register_namespace
was only introduced in lxml 2.3 (still beta)
I believe you can provide an nsmap
parameter (dictionary with prefix-uri mappings) when creating an element, but I don't think you can change it for an existing element. (there is an .nsmap
property on the element, but changing that doesn't seem to work. There is also a .prefix
property on the element, but that's read-only)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow