Sorry, I made a serious mistake in my last message. For clarity, toss the whole thing and use this instead: Greetings! I've run into a few snags related to namespace handling in LXML 1.1.1 (I'm using the bundled Windows distribution). First, I had hoped that the namespaces defined in the tree's root element nsmap attribute could be automatically included upon re-serialization. For example, given this source xml: <root xmlns="ns1"> <element /> </root> Split off <element> into a new tree: newtree = etree.ElementTree(element) And then reserialize newtree: result = etree.tostring(newtree.getroot()) Even though the root element of newtree contains the same nsmap as the source tree, the resulting output is <element /> and not <element xmlns='ns1' /> Is there some function or keyword in lxml that will case the namespace definitions in the nsmap attribute to be re-mapped into the output? I've tried to find such a thing if it exists using the docstrings and introspection but I've come up empty-handed. Second, one might think that the nsmap attribute would be 'just the ticket' for performing xpath searches: elements = mytree.xpath('//fred:someelement', mytree.getroot().nsmap) But this fails, because (following from the first example above) the nsmap attribute for <rootelement> yeilds {None:'ns1', 'fred':'ns2', 'bob':'ns3'} Note: the above xpath search succeeds if the None:'ns1' namespace is deleted from nsmap. Using a NoneType as a key in nsmap causes it to be unusable as far as the xpath function is concerned (and probably some other places as well.) Is there any workaround, other than creating (and updating) my own namespace dictionary within my code?