How to insert namespace and prefixes into an XML string with Python?
Suppose I have an XML string: <A> <B foo="123"> <C>thing</C> <D>stuff</D> </B> </A> and I want to insert a namespace of the type used by XML Schema, putting a prefix in front of all the element names. <A xmlns:ns1="www.example.com"> <ns1:B foo="123"> <ns1:C>thing</ns1:C> <ns1:D>stuff</ns1:D> </ns1:B> </A> Is there a way to do this (aside from brute-force find-replace or regex) using lxml.etree or a similar library? mzjn I don't think this can be done with just ElementTree. Manipulating namespaces is sometimes surprisingly tricky. There are many questions about it here on SO. Even with the more