I had a problem when using the lxml find () method to select a node in an XML file. Essentially, I'm trying to move a node from one XML file to another.
File 1:
<somexml xmlns:a='...' xmlns:b='...' xmlns:c='...'> <somenode id='foo'> <something>bar</something> </somenode> </somexml>
As soon as I analyze file 1 and find it:
node = tree.find('//*[@id="foo"]')
Node is as follows:
<somenode xmlns:a='...' xmlns:b='...' xmlns:c='...'> <something>bar</something> </somenode>
Notice that the namespaces found in the document are added to the node. However, nothing in this node uses any of these namespaces. How can I get around either A) not writing namespaces that are not used in the selected node, or B) deleting unused namespace names? If it is used in the selected node, then I will need it, but otherwise I would like to get rid of them. Any ideas? Thanks!
source share