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
I wish to set the namespace prefix in xml.etree. I found register_namespace(prefix, url) on
Share
register_namespacewas only introduced in lxml 2.3 (still beta)I believe you can provide an
nsmapparameter (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.nsmapproperty on the element, but changing that doesn’t seem to work. There is also a.prefixproperty on the element, but that’s read-only)