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
+1
A:
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)
Steven
2010-09-28 16:10:42